Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new class named RandomNumber. Write program to generate three double ty

ID: 3878753 • Letter: C

Question

Create a new class named RandomNumber. Write program to generate three double type number within range [0, 100]. Calculate the square root of the sum of those three numbers.

(i.e., if a, b and c are three random numbers, the result should be Math.sqrt(a + b + c))

Simulate the sample output:

(Since the numbers generated are random, you may not see the same numbers at each run)

Hint: if rand is defined as Random rand = new Random();

then  rand.nextDouble() will generate a double type number within range [0, 1].

rand.nextDouble() * 100 will generate a double type number within range [0, 100].

Submit  RandomNumber.java

Explanation / Answer

import java.util.Random;

public class RandomNumber {

public static void main(String[] args) {

Random rand=new Random();

double a,b,c;

a=rand.nextDouble()*100;

b=rand.nextDouble()*100;

c=rand.nextDouble()*100;

double result=Math.sqrt(a+b+c);

System.out.println("Square root of the three randaom numbers "+a +","+b+" and "+c +" is "+result );

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote