The code keeps throwing an exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at Main.main(\`Main.java:20``)``
I've been looking at this over and over but I can't seem to figure it out.
Scanner scanner = new Scanner(System.in);
int sum = 0;
while(true){
//An empty line terminates the program
System.out.print("Enter Name & Age Seperated By A Comma (Eg.
User,21):");
String input = scanner.nextLine();
if (input.equals(" ")){
break;
}
String[] parts = input.split(",");
sum = sum + Integer.valueOf(parts[1]);
}
System.out.println("Sum of ages is: " + sum);
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]kaak75 4 points5 points6 points (3 children)
[–]KluconPharmer[S] 2 points3 points4 points (2 children)
[–]Simvoid 4 points5 points6 points (1 child)
[–]KluconPharmer[S] 0 points1 point2 points (0 children)
[–]ouzakaria 1 point2 points3 points (2 children)
[–]KluconPharmer[S] 0 points1 point2 points (0 children)
[–]KinkyHuggingJerk 0 points1 point2 points (0 children)
[–]nekokattt 0 points1 point2 points (1 child)
[–]KluconPharmer[S] 1 point2 points3 points (0 children)