Write a program called GradeBook.java. This program should do the following:
1. Prompt the user to enter 3 grades one at a time, and read them in using Scanner (assume the grades are integer numbers).
2. Compute the average of the 3 grades.
3. Print the resulting average (do not worry about rounding the result, just print the value with all of the decimal places).
Here is an example of what the program output will look like (bold-italics indicate user input):
Enter grade 1: 89
Enter grade 2: 93
Enter grade 3: 72
84.666666667
import java.util.Scanner;
public class GradeBook {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int grade1, grade2, grade3;
System.out.print("Enter grade 1: ");
grade1 = keyboard.nextInt();
System.out.print("Enter grade 2: ");
grade2 = keyboard.nextInt();
System.out.print("Enter grade 3: ");
grade3 = keyboard.nextInt();
double average=(double) ((grade1+grade2+grade3)/3.0);
System.out.println(average);
keyboard.close();
}
}
Comments
Leave a comment