import java.util.Scanner;
public class InputLoop
{
public static void main(String[] args)
{
System.out.println("Enter an integer to continue or a non-integer to finish");
Scanner scan = new Scanner(System.in);
int input = scan.nextInt();
while(scan.hasNextInt())
{
System.out.println("Enter an integer to continue or a non-integer to finish");
scan.next();
}
}
}
这是我编写的第一个while循环,当它运行时,我必须输入一个数字两次才能继续打印“输入一个整数以继续......”感谢您的帮助!