title: Printing lines in reverse java
body: <p>I'm trying to wrap my head around a problem I have in a programming set.</p>
  
  <p>We're supposed to write code that reads from a file and prints it out. I get that, I can do it.</p>
  
  <p>What he wants us to do is have it print out in reverse.</p>
  
  <p>the file reads:</p>
  
  <pre><code>abc
  123
  987
  </code></pre>
  
  <p>He wants:</p>
  
  <pre><code>987
  123
  abc
  </code></pre>
  
  <p>The code, as it is, is as follows:</p>
  
  <pre><code>{
      FileReader n=new FileReader("F:\\Java\\Set 8\\output1.txt");
      Scanner in=new Scanner(n);
      int l;
      while (in.hasNext())
      {
          l=in.nextInt();
          System.out.println(l);      
      }
      in.close(); 
  }
  }
  </code></pre>
  
  <p>Yes, I am using java.io.*; and Scanner.</p>
  
  <p>What would be the simplest way to do this?</p>
  
  <p>EDIT EDIT EDIT</p>
  
  <p>Here's the improved code, where I try to put it into an array.</p>
  
  <p>The data in the array isn't printing out.</p>
  
  <pre><code>public static void main(String[] args) throws IOException
  {
      int[]Num=new int[20];
      Scanner in=new Scanner(new FileReader("F:\\Java\\Set 8\\output1.txt"));
      int k;
      for (k=0;k&lt;20;k++)
      {
          Num[k]=in.nextInt();
      }
      //in.close();
      for (k=20;k&lt;20;k--)
      {
          System.out.print(+Num[k]);
      }
      //in.close();   
  }
  </code></pre>