我已整夜编程,我再也找不到错误了:/:/ 如果intro == 1或2然后执行此操作..如果intro!= 1或2然后再次询问数字,直到数字为1或2 ...我找不到错误:/
do{
System.out.println("Enter number: ");
Scanner scanintro = new Scanner(System.in);
intro = scanintro.next();
}while (intro == ("1")|| intro == ("2"));
答案 0 :(得分:5)
do{
System.out.println("Enter number: ");
Scanner scanintro = new Scanner(System.in);
intro = scanintro.nextInt();
} while (intro == 1|| intro == 2);
答案 1 :(得分:1)
equals
你应该使用do {
System.out.println("Enter number: ");
Scanner scanintro = new Scanner(System.in);
intro = scanintro.next();
} while (intro != 1 || intro != 2);
来比较字符串,但它是一个int(我不知道你的intro变量的数据类型是什么,但你应该把它改成int)所以你可以检查它像这样:
{{1}}