/* GradeAverage.java by Craig Persiko
CS 111A In-class exercise solution
In-class exercise: Write a program that has the user enter
3 numeric homework grades, and outputs their average.
Make sure to use a floating point data type for the grades.
Use "printf" to show the average rounded to the nearest tenth (showing just 1 digit after the decimal point)
*/
import java.util.Scanner;
class GradeAverage
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double grade1, grade2, grade3, average;
System.out.println("Please enter 3 grades, separated by spaces");
grade1 = scan.nextDouble();
grade2 = scan.nextDouble();
grade3 = scan.nextDouble();
average = (grade1 + grade2 + grade3) / 3;
System.out.printf("Their average is: %.1f \n", average);
}
}
/* Sample Output:
[cpersiko@fog cs111a]$ javac GradeAverage.java
[cpersiko@fog cs111a]$ java GradeAverage
Please enter 3 grades, separated by spaces
9.5 7.5 8.3
Their average is: 8.4
[cpersiko@fog cs111a]$
*/
syntax highlighted by Code2HTML, v. 0.9