Question

In Java, define 4 int variables y1, y2, y3, y4. Input 4 integer numbers from console...

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.

Homework Answers

Answer #1
//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);
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
2. Write a java program to: Define 3 integer variables var4, var5, and var6. Initialize these...
2. Write a java program to: Define 3 integer variables var4, var5, and var6. Initialize these variables with numbers input from console Right shift values in var4, var5 and var6, so var6 will get var5’s value, var5 will get var4’s value and var4 will get var6’s value Calculate the average of these numbers and save it into variable avg Display the following message: “the average of numbers value4, value5 and value6 is average-value”. (value4, value5, value6 and average-value should be...
4-bit signed numbers X = x3 x2 x1 x0 Y = y3 y2 y1 y0 need...
4-bit signed numbers X = x3 x2 x1 x0 Y = y3 y2 y1 y0 need a logic simulation to read signed numbers x3, and y3. if x3 and y3 are equal to 0, read the number as is. if x3 and y3 are equal to 1, take the 2's complement of number.
Meant to be written in Java JDK 14.0 Generate four (4) integer numbers in range [0,...
Meant to be written in Java JDK 14.0 Generate four (4) integer numbers in range [0, 100]. Use Math methods to: (a) find the maximum and minimum numbers and display (b) calculate the absolute difference between the maximum number and minimum numbers, display
Write a java program to display a given range of integer numbers (0 to 9) in...
Write a java program to display a given range of integer numbers (0 to 9) in the following order: Example : given (5 to 9), the program displays 56789 67895 78956 89567 95678 The first line displays the min to max range. Each line that follows should display the next higher number except when it hits the maximum number. In that situation, the line wraps back to the minimum sequence. For this problem write a static method to do the...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Write a program that takes two numbers from the Java console representing, respectively, an investment and...
Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, and 20 years using the following formula: future value = investment * (1 + interest rate)year We will assume that the interest...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...