Why is my code not printing anything to stdout?

Posted by WM on Stack Overflow See other posts from Stack Overflow or by WM
Published on 2010-05-02T15:09:21Z Indexed on 2010/05/02 15:17 UTC
Read the original article Hit count: 273

Filed under:
|

I'm trying to calculate the average of a student's marks:

import java.util.Scanner;

public class Average

{

    public static void main(String[] args)
    {
        int mark;
        int countTotal = 0;  // to count the number of entered marks
        int avg = 0;        // to calculate the total average
        Scanner Scan = new Scanner(System.in);

        System.out.print("Enter your average: ");
        String Name = Scan.next();

        while (Scan.hasNextInt())
        {
            mark = Scan.nextInt();
            countTotal++;

            avg = avg + ((mark - avg) / countTotal);
        }


        System.out.print( Name + "  " + avg );
    } 
}

© Stack Overflow or respective owner

Related posts about java

Related posts about homework