이제 사용자가 자신의 ID 번호를 입력 할 수있는 프로그램을 만들려고합니다.
하지만 ID 번호 사용자가 얼마나 많은 숫자를 입력할지 모르기 때문에 어떻게해야할지 모르겠다. 예를 들어
:
나는 사용자의 싶어 두 사람의 ID 번호를 넣어 알고, 그래서 내 코드는 다음과 같이 될 것입니다 경우 나 사용자의 싶어 3 사람의 ID 번호를 넣어 알고있는 경우얼마나 많은 사람이 입력할지 모르는 경우에도 사용자의 입력을 허용하는 방법
//get 2 people's student ID
System.out.print("Enter the first people's student ID: ");
String ID1 = input.next();
System.out.print("Enter the second people's student ID: ");
String ID2 = input.next();
, 그래서 내 코드 같은 것 이 :
//get 3 people's student ID
System.out.print("Enter the first people's student ID: ");
String ID1 = input.next();
System.out.print("Enter the second people's student ID: ");
String ID2 = input.next();
System.out.print("Enter the third people's student ID: ");
String ID3 = input.next();
하지만 사용자가 입력 할 전화 번호가 몇 개인 지 알 수 있습니다. 얼마나 많은 숫자를 입력해야할지 모르겠다면, 사용자의 입력을 허용하고 입력 한 번호를 저장하려면 어떻게해야합니까?
어쩌면 루프를 시도? – bradimus
사용자에게 얼마나 많은 ID가 있는지 묻고, 반복하고 프롬프트 한 다음 사용자의 데이터를 배열에 넣습니다. – Li357
@AndrewLi 아마 ArrayList <> 더 구체적으로 그는 제한을 알지 못한다고 말합니다) – jonk