This is the code I have right now
for (int i = 0; i <= listOfPeople.length; i++){
String name = scnr.nextLine();
System.out.println("Person " + (i + 1) + ": ");
listOfPeople[i] = name;
}
List of people is a properly declared list of Strings with the length of a value the user sends in. The error that is happening is that when I run the program, I get this:
Person 1:
Jordan
Person 2:
Jordan
Person 3:
Jordan
Person 4:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at RGG.main(RGG.java:20)
I am not quite sure what is wrong, but I have tried removing the = in the for loop declaration, then I get this output:
Person 1:
Jordan
Person 2:
Jordan
Person 3:
After the third prompt, the code moves on and I cant type in anything there. Does anyone know what might be happening? Thanks in advance!