6 Replies Latest reply on Feb 13, 2008 7:02 PM by 807601

    Accessing Values from String Array

      Hello, I am trying to make a state and capitol array, then access it based on input of the state and have it print the state in JOptionPane MESSAGE.
      I am having trouble filter out the correct place in the array based on the input so it can print out.... was wondering if anyone could help. Appreciate it. Here is the code I have so far....

      import javax.swing.JOptionPane;
      import java.io.*;

      * myArray.java
      public class myArray {
      public myFinal() {
           String stat;
           for( int i=0; i<statesArray.length; ++i ){
                     stat = JOptionPane.showInputDialog("Enter the state which you would like to find the Capitol of. ");
           stat = (statesArray[0]);
                //the problem is right in here********
      JOptionPane.showMessageDialog(null, " " +statesArray[i][1] , "Robert T. Deems", JOptionPane.INFORMATION_MESSAGE);
      public static void main(String[] args) {
      new myArray();
      private String statesArray[][] = {
      {"Arkansas","Little Rock"},
      {"Iowa","Des Moines"},
      {"Louisiana","Baton Rouge"},
      {"Minnesota","St. Paul"},
      {"Missouri","Jefferson City"},
      {"Nevada","Carson City"},
      {"New Hampshire","Concord"},
      {"New Jersey","Trenton"},
      {"New Mexico","Santa Fe"},
      {"New York","Albany"},
      {"North Carolina","Raleigh"},
      {"North Dakota","Bismarck"},
      {"Oklahoma","Oklahoma City"},
      {"Rhode Island","Providence"},
      {"South Carolina","Columbia"},
      {"South Dakota","Pierre"},
      {"Utah","Salt Lake City"},
      {"West Virginia","Charleston"},
      class printState {
      public printState(String state, String city){

      public String toString(){
           if (state == (statesArray[i][0]))
      return " The Capital of: "+state+" is: "+city;
      private String state, city;