title: Program to find the maximum average out of given records. Input mismatch exception. string value goes null
body: <p>Program to find the maximum average out of given records. Input mismatch exception. string value became blank while iterating over for loop value i=1</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class MaxAvg {
  
      public static void main(String[] args) {
  
          Scanner sc = new Scanner(System.in);
          ArrayList&lt;Records&gt; rec = new ArrayList&lt;Records&gt;();
          int maxAvg = 0, maxIndex = 0;
          String s ="";
  
          for(int i=0;i&lt;3;i++)
          {
              s = sc.nextLine();
              int m1 = sc.nextInt();
              int m2 = sc.nextInt();
              int m3 = sc.nextInt();
              rec.add(new Records(s,m1,m2,m3));
          }
  
          for(int i=0;i&lt;3;i++)
          {
              int avg = (rec.get(i).m1 + rec.get(i).m2 + rec.get(i).m3 )/3;
              if(avg &gt; maxAvg)
              {
                  maxAvg = avg;
                  maxIndex = i;
              }
          }
  
          System.out.println(rec.get(maxIndex).name  + "   " + maxAvg);
  
      }
  
  }
  
  
  
  class Records
  {
      String name;
      int m1,m2,m3;
      public Records(String name, int m1, int m2, int m3) {
          super();
          this.name = name;
          this.m1 = m1;
          this.m2 = m2;
          this.m3 = m3;
      }
  }
  </code></pre>
  
  <p>this is the exception i am encountering</p>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException
      at java.util.Scanner.throwFor(Unknown Source)
      at java.util.Scanner.next(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at MaxAvg.main(MaxAvg.java:19)
  </code></pre>