arrayList를 반복 할 때마다 그 자체가 재설정됩니다. 결국 목표는 당신은 루프의 각 반복에서 max
를 재 선언하고 ArrayList에ArrayList는 루프 이후에 재설정을 계속합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
public class loops {
public static void main(String[] args) {
System.out.println("Do you want to calculate the most reoccuring answer?");
System.out.println("enter 'yes' or 'no'");
Scanner start = new Scanner(System. in);
String starter = start.nextLine();
boolean jax = true;
while (jax == true && starter.equals("yes")) {
Scanner answer = new Scanner(System. in);
System.out.println("Enter the answer choice");
int ans = answer.nextInt();
ArrayList <Integer> max = new ArrayList <Integer>();
max.add(ans);
Scanner goOn = new Scanner(System. in);
System.out.println("Any other grades?");
System.out.println("yes or no");
String procced = goOn.nextLine();
String str12 = "yes";
String str113 = "no";
if (procced.equals(str113)) {
jax = false;
System.out.print(max);
}
}
}
}
신규 사용자! 우리는 모두 좋은 답변/의견을 게시해야합니다. 이것이 처음 자바 프로그래머에게 합당한 질문이기 때문에 다운 voting을 자제하십시오. Stackoverflow에 오신 것을 환영합니다! 즐거운 시간을 갖기를 바랍니다. – Justin