gpt4 book ai didi

java - 如何将数字添加到长值

转载 作者:行者123 更新时间:2023-11-30 08:10:59 26 4
gpt4 key购买 nike

所以我有这个变量 long hashvalue 并且我想在它为真时向它添加数字。

我有这个数组 int arr[3][3] 和数字 -1, 1, 0, 0, -1, 1, 0, 0, -1在里面

我需要这样的东西:

if(array[i][j] == -1){
//add digit 2 to hashvalue
} else if(array[i][j] == 1){
//add digit 1 to hashvalue
} else if(array[i][j] == 0){
//add digit 0 to hashvalue
}

哈希值 = 210021002

最佳答案

您可以简单地为散列值创建一个字符串,然后通过 +(或 +=)运算符将数字添加到字符串中。要从字符串中接收长对象,可以使用 Long.parseLong() 函数。

String hashvalue = "";

// Add your digits to the String here
hashvalue += "1";

// Convert the String to a long
long finalHashvalue = Long.parseLong(hashvalue);

关于java - 如何将数字添加到长值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com