In: Computer Science
Write program#2 upload .java file.
2A) Write a java program that uses the Random class to generate a number in the range 21 to 64. Print the generated number.
2B) Using the Random class and nextInt(6), rolls two die generating two random numbers each in the range 1 through 6. Total by adding the two values together. Print the value of each die, and the total value.
2C) Using the Math class and sqrt(num), calculate the square root of integer twenty-two divided by integer seven, print the result formated to ten decimal places. Hint: the result of the division needs data conversion to support a double.
/*********************Program2.java*********************/
import java.util.Random;
public class Program2 {
public static void main(String[] args) {
Random random = new Random();
int genRandom =
random.nextInt(64) + 21;
System.out.println(genRandom);
int dice1 = random.nextInt(6) +
1;
int dice2 = random.nextInt(6) +
1;
int totalValue = dice1 + dice2;
System.out.println("Dice1: " + dice1 + ", Dice2: " + dice2 + ", Total Vale=ue: " + totalValue);
double result = Math.sqrt(22 / 7);
System.out.printf("Result is
%.10f", result);
}
}
/*****************output**************/
53
Dice1: 1, Dice2: 5, Total Vale=ue: 6
Result is 1.7320508076
Please let me know if you have any doubt or modify the answer, Thanks:)