Question

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 replaced with real values stored in variables var4, var5, var6 and avg)

This is meant to be written in Java 14.0

Homework Answers

Answer #1

Below is the code for given question. The question is not asking for Bitwise right shift of var4, var5 and var6, it asks for only normal shift which will have no effect on average value.

import java.util.Scanner;
public class Code {

 public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        double var4 = scan.nextDouble();
        double var5 = scan.nextDouble();
        double var6 = scan.nextDouble();
        scan.close();

        System.out.print("the average of numbers var4, var5 and var6 is" + avgg(var4, var5, var6) );
    }

  public static double avgg(double value4, double value5, double value6)
    {
        return (value4 + value5 + value6) / 3;
    }
}
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
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.
Define 2 variables vx and vy. Initialize vx and vy with numbers 100 and 200 respectively....
Define 2 variables vx and vy. Initialize vx and vy with numbers 100 and 200 respectively. Prompt user to enter 2 numbers, save them into vx and vy. This is meant to be done in MIPS assembly language.
3. The following is the formula to convert a Celsius degree to Fahrenheit degree: Fahrenheit =...
3. The following is the formula to convert a Celsius degree to Fahrenheit degree: Fahrenheit = (9/5) Celsius + 32 Write a program to prompt user to enter a Celsius degree, convert it to Fahrenheit and display Given an integer value which is the measurement of weight in ounce. Convert it to the format of: x pounds and y ounces. For example, if the given number is 100 ounces, it will be represented as 6 pounds and 4 ounces after...
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize...
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize it with value 9.99 (2) Given two integer variables var2 and var3, write a statement that gives var3 a value that is 4 more than the value of var2. (3) Define a double variable var4, initialize it with value 1234.56. Write a statement to change var4 so it will just hold one third (1/3) of the original value (4) Given four double variables var5,...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT