In Java, define 4 int variables y1, y2, y3, y4. Input 4 integer numbers from console to initialize these 4 variables. Calculate the average of the numbers in these variables and display message: “The average of numbers num1, num2, num3, num4 is theaverage-number”. The num1, num2, num3, num4 and the-average-number should be replaced by real numbers.
//TestCode.java import java.util.Scanner; public class TestCode { public static void main(String[] args) { int y1, y2, y3, y4; Scanner scan = new Scanner(System.in); System.out.print("Enter y1: "); y1 = scan.nextInt(); System.out.print("Enter y2: "); y2 = scan.nextInt(); System.out.print("Enter y3: "); y3 = scan.nextInt(); System.out.print("Enter y4: "); y4 = scan.nextInt(); double average = (y1+y2+y3+y4)/4.0; System.out.println("The average of numbers "+y1+", "+y2+", "+y3+", "+y4+" is "+average); } }
Get Answers For Free
Most questions answered within 1 hours.