나는이 코드를 가지고 있으며 사용자가 다음 입력을 기다릴 때 처음 건너 뛴 얼굴을 제외하고는 모든 것이 실행되고 있습니다. 여기 코드는 다음과 같습니다for 루프 건너 뛰기 문제
여기import java.util.Scanner;
public class mainThread {
public static int size;
public static int counter;
public static Scanner input = new Scanner(System.in);
public static String currentIn;
public static void main(String[] args){
System.out.println("Please type the desired amount of players: ");
size = input.nextInt();
String nameArray[] = new String[size];
for(int counter = 0; counter < size; counter++){
System.out.println("Please enter the name of player " + (counter+1));
currentIn = input.nextLine();
nameArray[counter] = currentIn;
System.out.println(nameArray[counter]);
}
}
}
콘솔의 말씀입니다 :
Please type the desired amount of players:
3
Please enter the name of player 1
Please enter the name of player 2
Jacob
Jacob
Please enter the name of player 3
그것은 완전히 처음 루프를 건너 뛰고 난 이유를 알아낼 수 없습니다. 시간 내 줘서 고마워!
'nextInt()'만이 in 값을 읽으며 나머지는 읽지 않습니다. 'input.nextLine();'을 추가하여 나머지 라인을 무시할 수 있습니다. –