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.
Java Using NetBean Write a program to define an integer variable named as roomNumber. Assign 408...
Java Using NetBean Write a program to define an integer variable named as roomNumber. Assign 408 to the variable. Then display a message in System.out as “The programming class is in room ”+roomNumber.
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,...
Write a program to do the following. JAVA CODE • Input an integer n. • Create...
Write a program to do the following. JAVA CODE • Input an integer n. • Create a BinarySearchTree S inserting the keys 1, 2, . . . , n in that order, which will result in a completely-skewed tree. • Measure the time to search for n + 1 in S. 4 • Display the time taken for search.
JAVA (Don't make it too complicated) Write a program that prompts the user for the name...
JAVA (Don't make it too complicated) Write a program that prompts the user for the name of a text file. The file should consist of a sequence of integers, one integer per line. The program will read in each line (using nextLine()), parse it as an int (using Integer.parseInt()), and report the number of values and their average. The average should be computed as a double. Your program should do some basic exception handling: (1) If the file cannot be...
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 =...
Write a C program Design a program that uses an array to store 10 randomly generated...
Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
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....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT