← all problems

Average of four test scores 🌶️🌶️

test1, test2, test3 and test4 are four whole-number test scores. The locked line at the bottom prints a variable named average (a double you have to create) holding their average, including any decimal part. Write the code in the box that declares average and gives it the right value. Watch out: dividing an int by an int throws away the decimal part before the answer is ever stored in a double. Your code will be tested with several different sets of scores.

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        int test1 = 90;
        int test2 = 85;
        int test3 = 92;
        int test4 = 91;
        // ---- write your code below ----
        System.out.println(average);
    }
}