I have a code here that creates an array and puts in people's names into it. However, the first array does not get recorded.
Scanner newscan = new Scanner(System.in);
System.out.println("How many people in the group?");
int groupnum = newscan.nextInt();
String[] people = new String[groupnum];
System.out.println("Put in the names of the people in the group");
String name;
int i = 0;
do{
System.out.println("Input Name");
name = newscan.nextLine();
people[i] = name;
i++;
}while(i<groupnum);
The console shows results like this:
How many people in the group?
5
Put in the names of the people in the group
Input Name
Input Name
John
Input Name
Bob
Input Name
Denis
Input Name
Andrew
I have tried using the debugger on IntelliJ, and it shows that whatever value I put in the first array, gets ignored and is set as a "" null value.
I have no idea to approach this problem. It would be very helpful if you can tell me what part of my code is causing this problem and how to fix it.