Advertisement
therrontelford

State Capitals Quiz 2D Matrix

Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class StateCapitals {
  3.  
  4.     public static void main(String[] args) {
  5.         //create an array of state capitals and their states
  6.         Scanner kb = new Scanner(System.in);
  7.         int counter = 0;  // I did not immediately recognize I needed this
  8.         String[][] capitals = {
  9.                 {"Arkansas" , "Little Rock"},
  10.                 {"Texas", "Austin"},
  11.                 {"Louisiana", "Baton Rouge"},
  12.                 {"New Mexico", "Santa Fe"}
  13.         };
  14.    
  15.         for (int i=0; i<capitals.length; i++) {
  16.             String temp;
  17.             System.out.println("What is the capital of "+ capitals[i][0]);
  18.             temp = kb.nextLine();
  19.             if (temp.equalsIgnoreCase(capitals[i][1])) {
  20.                 System.out.println("That is correct");
  21.                 counter++;
  22.             }
  23.             else
  24.                 System.out.println("The correct answer is "+ capitals[i][1]);
  25.         }
  26.         System.out.println("You got "+ counter + " correct.");
  27.  
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement