2017-09-16 1 views
-2

나는이 코드를 가지고 완벽하게 작동하지만 코드에서 이름과 점수를 사용하는 대신 이름이 입력되지 않을 때까지 원하는 모든 이름과 점수를 입력 할 수 있기를 원합니다. 누르면 아무것도 입력되지 않을 때 "입력".무한 배열을위한 루프

Scoreboard highscores = new Scoreboard(3); 

String[] names = { "Rob", "Mike", "Rose", "Robert", "Gudelio", "Anna", "Paul", "Bob" }; 
int[] scores = { 750, 1105, 590, 5690, 4003, 660, 720,600 }; 


for (int i = 0; i < names.length; i++) { 
    GameEntry gE = new GameEntry(names[i], scores[i]); 
    System.out.println("Adding " + gE); 
    highscores.add(gE); 
    System.out.println(" Scoreboard: " + highscores); 
} 
} 
+0

당신이라고 원하는 클래스를'Scanner'.에서 [자바 튜토리얼 (https://docs.oracle.com/javase/tutorial/ essential/io/scanning.html)는 어떻게 사용하는지 설명하고있다. –

+0

스캐너는 hasNext() 함수를 가지고있다. – progyammer

+0

나는 스캐너 사용법을 알고 있지만, 유한 배열을 만드는 방법을 모른다. –

답변

0
Scanner input = new Scanner(System.in); 

while(input.hasNext()) { 
    // do what you need to do with the input here. 
    // when the first empty string is encountered the loop will exit   
}