title: How to print txt file with file numbers using I/O?
body: <p>i am printing a .txt file using the <code>Scanner</code> and I want to print the file with line numbers. here is my code. My problem is that the line numbers aren't incrementing.</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  
  public class List 
  {
    public static void main(String[] args) throws IOException
    {
      int line =1;
      File f = new File("src/List.txt");
  
  
      Scanner sc = new Scanner(f);
      while(sc.hasNext())
      {
          int num = 1;
          System.out.print(num);
          System.out.println(sc.nextLine());
          num++;
      }
    }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1Bird
  1Dog
  1Cat
  1Elephant
  1Tiger
  1Zebra
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>1 Bird
  2 Dog
  3 Cat
  4 Elephant
  5 Tiger
  6 Zebra
  </code></pre>