【发布时间】:2020-09-06 15:23:17
【问题描述】:
因此,当我输入一个 12 位长数字时,它会正确计算校验和。但如果我输入一个 13 位的长数字,它就会出错。
public static void checksum(long l) {
long x1 = l / 100000000000l % 10;
long x2 = l / 10000000000l % 10;
long x3 = l / 1000000000 % 10;
long x4 = l / 100000000 % 10;
long x5 = l / 10000000 % 10;
long x6 = l / 1000000 % 10;
long x7 = l / 100000 % 10;
long x8 = l / 10000 % 10;
long x9 = l / 1000 % 10;
long x10 = l / 100 % 10;
long x11 = l / 10 % 10;
long x12 = l / 1 % 10;
long x13 = l % 10;
long calculation = x1+(x2*3)+x3+(x4*3)+x5+(x6*3)+x7+(x8*3)+x9+(x10*3)+x11+(x12*3)+x13;
System.out.println(calculation);
}
【问题讨论】:
-
你能举出给定输入、输出和预期输出的例子吗?并分享你如何调用方法的代码,错误也可能在那里
-
当输入为 3729483022008 时,预期输出为 100。我得到的是 107
-
你打电话给
3729483022008还是3729483022008L,结果是91 -
l / 1 % 10与l % 10相同。 -
我打电话给 3729483022008L