java - 如何向长值添加数字

标签 java long-integer digit

所以我有这个变量 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/

相关文章:

java - 在 Intellij IDEA 中打开 Gradle 项目时出现问题

java - JBPM 3.2.3 示例项目与 MAVEN 的集成

java - 如何检查 JSON key 是否存在?

java - 在文件中从 Java 编写 Long 并在 C++ 中读取它

java - 从 Java 中的文本文件中读取 long 类型

C:如何将多位数字分解成单独的变量?

Java同一个List中的多个子类型和父类(super class)型

java - 使用 == 运算符进行原始和对象比较

regex - 三位数字,每两位正则表达式后跟破折号

数字求和算法?