扫描仪停止读取扫描仪类中第一个整数后的整数。即使有空格,我如何让它全部读出来?
System.out.println("please enter numbers to decrypt");
num = sc.nextInt(); // number to decrypt
result = sourcetext.charAt(num); //retrives each character that num points it to from sourcetext
int i=0;
for(i = 0; i < num; i++) {
temp= sourcetext.charAt(sourcetext.indexOf(i));
}
System.out.println(sourcetext.charAt(sourcetext.indexOf(i)));
答案 0 :(得分:1)
如果需要允许用户输入由空格分隔的多个数字,则需要使用scanner.nextLine()代替。
String inputNumbers = scanner.nextLine();
String[] numbers = inputNumbers.split(" ");
for (number : numbers) [
// handle numbers
}