这是我的代码,它还没有完成,但是当我测试时遇到了问题,我运行了代码并输入“ 2”,然后根据条件输入了“ y”,但是它退出了循环并打印了[ 2]作为输出
import java.util.Scanner;
import java.util.ArrayList;
public class enterInts {
public static void main(String[] args) {
//int counter=0;
int number=0;
String continu="y";
ArrayList<Integer> intList= new ArrayList<Integer>();
while (continu=="y") {
Scanner sc= new Scanner(System.in);
Scanner continuer=new Scanner(System.in);
System.out.print("Enter an integer:");
number=sc.nextInt();
System.out.print("Would you like to coninue? Enter y for yes or n for no");
continu=continuer.nextLine();
intList.add(number);
}
System.out.print(intList);
}
}
谢谢