title: Using Shellsort to sort a list of countries by population (Java)
body: <p>In my program, I have a class Sorting, that inputs a file called CountryUnsortedFormat that contains a random list of countries and their populations. The class is supposed to use shellsort to sort the countries by population and display them on the screen.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package assignment3;
  import java.io.PrintWriter;
  import java.io.File;
  import java.util.Arrays;
  import java.util.Random;
  import java.util.Scanner;
  
  public class Assignment3 {
  
  public static void main(String[] args) throws Exception{
      //Array for handling list of countries
      String[] line = new String[238];
      //read list of countries into array
      readInArray(line);
      //unsort the array
      unSort(line);
  
  
  }
  
   static void readInArray(String[] line) throws Exception{
       Scanner stdIn = new Scanner(new File("C:/Users/Vicki/Desktop/CountrySortedFormat.txt"));
  
       //Read in countries from sorted file into an array
      int k=0;
      while (stdIn.hasNextLine()){    
          line[k]=stdIn.nextLine();   
          k++;
      }
   }
  
   static void unSort(String[] line) throws Exception{
      PrintWriter out = new PrintWriter("C:/Users/Vicki/Desktop/CountryUnsortedFormat.txt");
      //Pick a random int from 1 to 238 called where
      //Write where into Unsorted Country Format file
      //Make where null
      //Repeat until all 238 countries are written in random order
      int j = line.length-1;
      Random r = new Random();
      while (j &gt; 0){
          int where = r.nextInt(j)+1;
          out.println(line[where]);
          line = pop(where, line);
          j--;
      }
      out.close();
  
   }
  
   static String[] pop(int index, String[] line){
       String[] newLine = new String[line.length-1];
       int offset = 0;
       for (int i = 0; i&lt;line.length; i++){
           if(i == index){
               offset = 1;
               continue;
           }
           newLine[i - offset] = line[i];
       }
       return newLine;
   }
  
  }
  
  class Sorting {
  
  public static void main(String[] args) throws Exception{
  
      //Array for handling list of countries
      String[] line = new String[238];
  
      readInArray(line);
      shellsort(line);
  
      System.out.println(Arrays.toString(line));
  
  }
  
  static void readInArray(String[] line) throws Exception{
      Scanner stdIn = new Scanner(new File("C:/Users/Vicki/Desktop/CountryUnsortedFormat.txt"));
  
      //Read in countries from unsorted file into an array
      int k=0;
      while (stdIn.hasNextLine()){    
          line[k]=stdIn.nextLine();   
          k++;
      }
  }
  
  static void shellsort(String[] line){
      int j;
      for(int gap = line.length-1/2; gap &gt; 0; gap /= 2){
          for(int i = gap; i &lt; line.length-1; i++){
              String tmp = line[i];
              for (j = i; j &gt;= gap &amp;&amp; getPopulation(line, j-gap) &gt; getPopulation(line, i); j -= gap){
                  line[j] = line[j -gap];
              }
              line[j] = tmp;
          }
      }
  }
  
  static int getPopulation(String[] line, int index){
      String populationString = line[index].substring(50,65).trim().replaceAll(",","");
      int population = Integer.parseInt(populationString);
      return population;
  }
  
  
  }
  </code></pre>
  
  <p>My classes work separately but when put together my program doesn't print to the screen. All it shows is "BUILD SUCCESSFUL (total time: 0 seconds)"</p>
  
  <p>What am I doing wrong?</p>