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
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.
Problem 3. Let Y1, Y2, and Y3 be independent, identically distributed random variables from a population...
Problem 3. Let Y1, Y2, and Y3 be independent, identically distributed random variables from a population with mean µ = 12 and variance σ 2 = 192. Let Y¯ = 1/3 (Y1 + Y2 + Y3) denote the average of these three random variables. A. What is the expected value of Y¯, i.e., E(Y¯ ) =? Is Y¯ an unbiased estimator of µ? B. What is the variance of Y¯, i.e, V ar(Y¯ ) =? C. Consider a different estimator...
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
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 =...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
IT 168                                         &nb
IT 168                                                                                          Fall 2020 Program 4 Due Date: October 21 at 11:55 PM Problem: A simulation program is needed to determine if the ISU Quiz Bowl Team should comprise mainly of genius students or regular students. A primary requirement of this program that is different from your earlier assignments is that you are required to create 2 different Java classes in the design of your program. Here are some other design details that may be helpful: Design: The classes should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT