import java.util.Scanner;
public class ProgramAssignment1 {
public static void main(String[] args) {
reader();
}
public static void reader() {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the Number of Students you would like to input for");
int count = input.nextInt();
int[] scores = new int[count];
String[] name = new String[count];
for (int i = 1; i <= count;i++) {
System.out.println("Please input the students names ");
name[i] = input.nextLine();
System.out.println("What is there score?");
scores[i] = input.nextInt();
}
for (int a = 1; a <= 10; a++) {
System.out.print(name[a]);
System.out.print(" "+scores[a]);
}
System.out.println();
}
}
so basically i need user input to an array but it keeps giving me the same error
Example run:
Please enter the Number of Students you would like to input for
2
Please input the students names
What is there score?
5
Please input the students names
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at ProgramAssignment1.reader(ProgramAssignment1.java:18)
at ProgramAssignment1.main(ProgramAssignment1.java:7)
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)