【发布时间】:2016-05-18 23:32:08
【问题描述】:
if (diceValues == null || diceValues.length() == 0) return 0;
int temp;
int val = 0;
Scanner scanner = new Scanner(diceValues);
while (scanner.hasNext()) {
temp = scanner.useDelimiter(" ").nextInt();
if (temp == 1) val += 100;
if (temp == 5) val += 50;
}
diceValue 是这样的字符串:“1 2 3 4 5”,扫描仪总是跳过最后一个数字。所以 int val(value) 总是比它应该的小。
【问题讨论】:
-
你是否正确调试了这个程序,因为我可以看到所有值都从扫描仪中正确读取
-
你怎么知道它跳过了最后一个数字?我刚刚用
System.out.println(temp)试了一下,它显示了所有 5 个数字。
标签: java string int java.util.scanner