public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
int i=0;
int arr[] = new int[10];
while(scan.hasNext()){
arr[i++] = scan.nextInt();
System.out.println("sud");
}
System.out.println("hello");
}
}
如果输入是1 2 3 4 5
那么它会打印5次。 sud意味着while循环正在工作,但它不会进入System.out.println("hello");
行或超出它。while循环后的执行流程java
也许是因为:scan.hasNext():) –
我猜如果(i> = arr.length)break;'。在'while'循环中插入这个_first_语句。 –
输入1,2,3,4,5后输入 - 你会看到'sud' 5次之后按Ctr + Z,如果你在windows上其他可能是Ctrl + D在Linux上。 – SomeDude