im writing this code so the user would enter his/her name and followed by his/her marks to get the a
- by WM
What if the user wanted to enter his/her grades in the following way:
Will 23, 34, 45, 45 how would i get
rid of the commas
public class StudentAverage
{
public static void main(String[] args)
{
int markSum = 0;
double average = 0;
Scanner input1 = new Scanner(System.in);
System.out.print("Enter student record : ");
String name = input1.next();
Scanner input2 = new Scanner(input1.nextLine());
int countTotal = 0;
while (input2.hasNextInt())
{
countTotal++;
markSum += input2.nextInt();
}
average = markSum / countTotal; // to calculate the total average
System.out.print( name + " " + average );
}
}