Question

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

Homework Answers

Answer #1
import java.util.Random;

public class FourRandom {

    public static void main(String[] args) {
        Random random = new Random();
        int n1 = random.nextInt(101);
        int n2 = random.nextInt(101);
        int n3 = random.nextInt(101);
        int n4 = random.nextInt(101);
        System.out.println("Random numbers generated are " + n1 + ", " + n2 + ", " + n3 + " and " + n4);

        int max = Math.max(Math.max(n1, n2), Math.max(n3, n4));
        int min = Math.min(Math.min(n1, n2), Math.min(n3, n4));
        System.out.println("Maximum: " + max);
        System.out.println("Minimum: " + min);

        System.out.println("Difference between maximum and minimum is " + Math.abs(max - min));
    }
}

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
Meant to be written in Java JDK 14.0 Three double variables a, b, and c represent...
Meant to be written in Java JDK 14.0 Three double variables a, b, and c represent the length of 3 sides of a triangle. Write a program to determine if the triangle is right triangle. Find the hypotenuse side first.
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.
Write a method using JAVA called "maximum4" that returns the maximum of 4 decimal numbers. Use...
Write a method using JAVA called "maximum4" that returns the maximum of 4 decimal numbers. Use the "math.max" method to implement "maximum4". The user should enter the 4 values and the program determines the maximum and then display the result. The steps for the Project could be the following: Create the Maximum4 method that includes the math.max Define and enter the variables Apply the Maximum4 method you created to find the maximum of the 4 decimal numbers you entered and...
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is...
JAVA a. An integer is a "Lucky Number" if it is divisible by 7 or is divisible by 11 and it is in the range 1000 through 4000. Write a Boolean expression that is true if and only if myNum (an int variable) contains a Lucky Number. b. Let a and b represent the length and the width of a rectangle. The length of the diagonal of the rectangle can be calculated by the following mathematical expression. diagonalLength = squareRoot(a...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined as follows: int myRandomNum () { return rand()%100 + 1; } Now, write a program (code fragment) that repeatedly generates and prints random integers in the range [1, 100]. The program must stop when the absolute value of the difference between successive printed values is less than 5. Two sample output is given to help you understand the problem: 1. The program can possibly...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
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)...
A 4-number bicycle combination lock has four rings with numbers 0 through 9, as in the...
A 4-number bicycle combination lock has four rings with numbers 0 through 9, as in the above picture. Write a method that accepts two ints: 1) starting: the current numbers of the lock (assume you will always get a 4-digit int) and 2) target: the combination required to unlock (assume you will always get a 4-digit int). Return the minimum number of "twists" to unlock the lock. Twists can either be "up" or "down." A twist up increases the number...
A program for generating random numbers on a computer is to be tested. The program is...
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 12 8 8 5 11 11 8 11 13 13 (a) Find the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT