You are on page 1of 1

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.util.Scanner;

/**
*
* @author User
*/
public class JavaApplication1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

int counter = 0, total = 0, average = 0,number = 0, totalcount = 0;

Scanner input = new Scanner(System.in);//Creating object of Scanner class


to take keyboard input
System.out.println("Input the first grade, or 0 to stop");

number = input.nextInt();//taking input from keyboard


//number zero(0) is the sentinel value

while (number != 0) {
total=total+number;//adding current number to new added number then
placing it again in total variable
counter++;//incrementing the count
totalcount = counter;//placing the current count to a temporary
variable

System.out.println("Input the next grade, or 0 to stop");


number=input.nextInt();

if(counter != 0){
average = total/totalcount;
System.out.println("Your average grade is "+average);//Printing average
of all the grades inputted
System.out.println(total);
System.out.println(totalcount);
}

else
{
System.out.println("No grade were entered");
}
}
}

You might also like