fork(1) download
  1. class Challenge1_6
  2. {
  3. public static void main(String[] args)
  4. {
  5. // 1. Declare 3 int variables called grade1, grade2, grade3
  6. // and initialize them to 3 values
  7. int grade1 = 78;
  8. int grade2 = 95;
  9. int grade3 = 84;
  10.  
  11. // 2. Declare an int variable called sum for the sum of the grades
  12. int sum;
  13. // 3. Declare a variable called average for the average of the grades
  14. double average;
  15. // 4. Write a formula to calculate the sum of the 3 grades (add them up).
  16. sum = grade1 + grade2 + grade3;
  17. // 5. Write a formula to calculate the average of the 3 grades from the sum using division and type casting.
  18. average = sum / 3.0;
  19. // 6. Print out the average
  20. System.out.println(average);
  21. }
  22. }
Success #stdin #stdout 0.06s 33076KB
stdin
Standard input is empty
stdout
85.66666666666667