title: Using while-loop to read from a file
body: <p>My question is: How do I use a while-loop to read inputs from a file ??</p>
  
  <p>I wrote this code and I wonder how can I write it again in another way using a While-loop.</p>
  
  <hr>
  
  <pre><code>Scanner infile = new Scanner(new FileReader("while_loop_infile.in"));
  
      int sum;
      int average;
      int N1, N2, N3,N4,N5, N6, N7, N8, N9, N10;
  
      N1= infile.nextInt();
      N2= infile.nextInt();
      N3= infile.nextInt();
      N4= infile.nextInt();
      N5= infile.nextInt();
      N6= infile.nextInt();
      N7= infile.nextInt();
      N8= infile.nextInt();
      N9= infile.nextInt();
      N10= infile.nextInt();
  
      sum = N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9 + N10;
      average = sum / 10;
  
      System.out.println("The sum is " + sum);
      System.out.println("The average is " + average);
  
      infile.close();
  </code></pre>
  
  <p>-------------------- This is the input file ------------------------------</p>
  
  <pre><code>10
  20
  30
  40
  50
  60
  70
  80
  90
  100
  </code></pre>