I am a beginner in Java and I would appreciate it if someone could help me figure out what to do with the rest of the code. I have already written some code but I can’t figure out the rest of the formulas. Can someone please help me?
Here are the instructions:
In the code below, type in three made up int grades and then sum and average them. Use casting to report the result as a double. For example, if the grades are 90, 100, and 94, the sum of the three numbers is 90 + 100 + 94 = 284, and the average is the sum 284 divided by 3 which casted to a double is 94.666667. You should use your variables instead of the numbers in your formulas. Type in three made up int grades and then sum and average them. Use type casting to report the result as a double.
Here is my code so far:
public class Challenge1_6
{
public static void main(String[] args)
{
// 1. Declare 3 int variables called grade1, grade2, grade3
// and initialize them to 3 values
int grade1 = 78;
int grade2 = 95;
int grade3 = 84;
// 2. Declare an int variable called sum for the sum of the grades
int sum = grade1 + grade2 + grade3;
// 3. Declare a variable called average for the average of the grades
int average = sum / 3;
// 4. Write a formula to calculate the sum of the 3 grades (add them up).
// 5. Write a formula to calculate the average of the 3 grades from the sum using division and type casting.
// 6. Print out the average
}
}