Java error: reached end of file while parsing

Good evening, everyone. I am trying to make a Java program that will prompt users to answer the name of the capital of each city. However, my code is giving the following error: reached end of file while parsing

           System.out.println (element[0] + " - " + element[1] );

I have tried a few other method but it is still not running properly. I would greatly appreciate any help. The following is the code :

public class StateCapitalQuiz {
   public static void main(String[] args) {
       String[][] states = {
               {"Alabama", "Montgomery"},
               {"Alaska", "Juneau"},
               {"Arizona", "Phoenix"},
               {"Arkansas", "Little Rock"},
               {"California", "Sacramento"},
               {"Colorado", "Denver"},
               {"Connecticut", "Hartford"},
               {"Delaware", "Dover"},
               {"Florida", "Tallahassee"},
               {"Georgia", "Atlanta"},
               {"Hawaii", "Honolulu"},
               {"Idaho", "Boise"},
               {"Illinois", "Springfield"},
               {"Maryland", "Annapolis"},
               {"Minnesota", "Saint Paul"},
               {"Iowa", "Des Moines"},
               {"Maine", "Augusta"},
               {"Kentucky", "Frankfort"},
               {"Indiana", "Indianapolis"},
               {"Kansas", "Topeka"},
               {"Louisiana", "Baton Rouge"},
               {"Oregon", "Salem"},
               {"Oklahoma", "Oklahoma City"},
               {"Ohio", "Columbus"},
               {"North Dakota", "Bismark"},
               {"New York", "Albany"},
               {"New Mexico", "Santa Fe"},
               {"New Jersey", "Trenton"},
               {"New Hampshire", "Concord"},
               {"Nevada", "Carson City"},
               {"Nebraska", "Lincoln"},
               {"Montana", "Helena"},
               {"North Carolina", "Raleigh"},
               {"Missouri", "Jefferson City"},
               {"Mississippi", "Jackson"},
               {"Massachusetts", "Boston"},
               {"Michigan", "Lansing"},
               {"Pennsylvania", "Harrisburg"},
               {"Rhode Island", "Providence"},
               {"South Carolina", "Columbia"},
               {"South Dakota", "Pierre"},
               {"Tennessee", "Nashville"},
               {"Texas", "Austin"},
               {"Utah", "Salt Lake City"},
               {"Vermont", "Montpelier"},
               {"Virginia", "Richmond"},
               {"Washington", "Olympia"},
               {"West Virginia", "Charleston"},
               {"Wisconsin", "Madison"},
               {"Wyoming", "Cheyenne"}
       System.out.println("State-Capital Pairs:");
       int correctCount = 0;
       Scanner scanner = new Scanner(;
       for (String[] state : states) {
           String capital = state[1];
           System.out.print("Enter the capital of " + state[0] + ": ");
           String userAnswer = scanner.nextLine();
           if (userAnswer.equalsIgnoreCase(capital)) {
       System.out.println("Total correct answers: " + correctCount);
   public static void bubbleSort(String[][] array) {
       int n = array.length;
       for (int i = 0; i < n; i++) {
           for (int j = 0; j < n - i - 1; j++) {
               if (array[j][1].compareToIgnoreCase(array[j + 1][1]) > 0) {
                   String[] temp = array[j];
                   array[j] = array[j + 1];
                   array[j + 1] = temp;
   public static void displayArray(String[][] array) {
       for (String[] element : array) {
           System.out.println (element[0] + " - " + element[1] );

Herein would like the problem, you don’t close that for loop, or that function.

Yes, I know this is where the problem lies, but I have tried different things, and it still doesn’t resolve the issue. Can you pinpoint precisely how that code is supposed to look for it to run? Maybe I am overlooking something.

Well, here’s an example function:

public class thing {
    public static void something() {
        for (int i=0; i < 20; i++) {

Your code is missing those last three closing brackets.

1 Like