im writing this code so the user would enter his/her name and followed by his/her marks to get the a
Posted
by WM
on Stack Overflow
See other posts from Stack Overflow
or by WM
Published on 2010-05-16T17:09:29Z
Indexed on
2010/05/16
17:20 UTC
Read the original article
Hit count: 197
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 );
}
}
© Stack Overflow or respective owner