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
import java.util.ArrayList;
import java.util.Scanner;
public class MaxAvg {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Records> rec = new ArrayList<Records>();
int maxAvg = 0, maxIndex = 0;
String s ="";
for(int i=0;i<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<3;i++)
{
int avg = (rec.get(i).m1 + rec.get(i).m2 + rec.get(i).m3 )/3;
if(avg > 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;
}
}
this is the exception i am encountering
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)