The program is supposed to end and give the amount of correct answers once the last question is answered. Instead the program goes back to the initial question in the loop. "What is the capital of Alabama"
package exercise09_17;
import java.util.Scanner;
public class exercise09_17 {
static Scanner input = new Scanner(System.in).useDelimiter("\r\n");
public static void main(String[] args) {
int correctAnswer = 0;
String [][] grid = {
{"Alabama", "California", "Delaware", "Florida", "Georgia",
"Hawaii", "Idaho", "Kansas", "Lousiana", "Maryland", "New Mexico", "Oregon",
"Pennsylvania", "Rhode Island", "South Carolina", "Texas", "Utah", "Virgina",
"West Virginia"},
{"Montgomery", "Sacramento", "Dover", "Tallahassee", "Atlanta",
"Honolulu", "Boise", "Topeka", "Baton Rouge", "Annapolis", "San Jose", "Salem",
"Harrisburg", "Providence", "Columbia", "Austin", "Salt Lake City", "Richmond",
"Charleston"}};
for(int i = 0; i< grid.length; i++){
for(int k = 0; k < grid[i].length; k++ ){
System.out.println("What is the capital of " + grid[0][k] + "?");
String capital = input.next();
String answer = grid[1][k];
if(capital.equalsIgnoreCase(answer)){
correctAnswer ++;
System.out.println("Your answer is correct");
}
else
System.out.println("The correct answer should be " + answer);
}
}
System.out.println("The correct count is " + correctAnswer);
}
}