title: Sorting Arrays from 2010 Census in Java
body: <p>I finished this program and something went wrong. By this I mean its not printing out what it needs to.  It is supposed to take the population from the census, along with the state names, and sort it from smallest to largest state.  When I run the project it prints out Alabama and its population 50 times,instead of all the states from smallest to largest population, I am unsure what to do, I could really use some help, please. An example of the census is as follows...
  Each of these would be on separate lines:</p>
  
  <blockquote>
    <p>Alabama,4779736<br> 
    Alaska,710231<br> 
    Arizona,6392017</p>
  </blockquote>
  
  <p>Here is the program:</p>
  
  <pre><code>    public static void main(String[] args) throws IOException {
      File f = new File("census2010.txt");
      if(!f.exists()) {
          System.out.println( "f does not exist ");
      }
      Scanner infile = new Scanner(f);
      infile.useDelimiter ("[\t|,|\n|\r]+");
      final int MAX = 50;
      int [] myarray = new int [MAX];
      String[] statearray = new String[MAX];
      int fillsize;
  
  
      fillsize = fillarray (myarray, statearray, infile);
      printarray (myarray, fillsize, prw);
      sortarray(myarray, statearray, fillsize);
  
  }
  
  public static int fillarray (int[] num, String[] states, Scanner infile) throws FileNotFoundException{
  
      int retcnt = 0;
      int pop;
      String state;
      state = infile.next();
      pop = infile.nextInt();
      for( int count = 0; count &lt; 50; count++){
          System.out.println(state + " " + pop + " ");
          states[retcnt] = state;
          num[retcnt] = pop;
          retcnt++;
      }
  
      return (retcnt);
  }
  
  public static void printarray (int[] num, int fillsize, PrintWriter prw){
      for (int counts = 0; counts &lt; fillsize ; counts++){
          System.out.println("For the position ["+counts+"] the value is " + num[counts]);
          prw.println("For the position ["+counts+"] the value is " + num[counts]);
      }
      return;
  }
  
  public static void  sortarray(int[] poparray, String[] statearray, int fillsize){
  
      for( int fill = 0; fill &lt; fillsize -1; fill = fill+1){
          for ( int compare = fill+1; compare &lt; fillsize; compare++){
              if( poparray[compare] &lt; poparray[fill]){
  
                  int poptemp = poparray[fill];  
                  poparray[fill] = poparray[compare]; 
                  poparray[compare]  = poptemp;
              // do I need something here?    
                  String statetemp = statearray[fill];  
                  statearray[fill] = statearray[compare]; 
                  statearray[compare]  = statetemp;
              }
          }
      }
  }
  </code></pre>
  
  <p>I think my problem is in the sort array, but what am I doing wrong?</p>