In: Computer Science
java please
1. Write a Java program to generate random numbers in the following range
a. 1 <=n <= 3
b. 1 <= n <= 200
c. 0 <= n <= 9
d. 1000 <= n <= 2112
e. -1 <= n <= 5
2. Write statements that assign random integers to the variable n in the following ranges:
a) 1 ≤ n ≤ 2
b) 1 ≤ n ≤ 100
c) 0 ≤ n ≤ 9
d) 1000 ≤ n ≤ 1112
e) –1 ≤ n ≤ 1
f) –3 ≤ n ≤ 11
Put these statements in Java program and run it.
3. Write a complete Java application to prompt the user for the double radius of a sphere, and
call method sphereVolume to calculate and display the volume of the sphere. Use the following statement
to calculate the volume:
double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 )
import java.util.*;
class Hello {
public static void main(String[] args) {
Random r = new Random();
// r.ints(x,y+1).findFirst().getAsInt() will return a random integer in the
// range [x,y]
int a = r.ints(1, (3 + 1)).findFirst().getAsInt();
// a will get a random value in the range [1,3]
int b = r.ints(1, (200 + 1)).findFirst().getAsInt();
// b will get a random value in the range [1,3]
int c = r.ints(0, (9 + 1)).findFirst().getAsInt();
// c will get a random value in the range [1,3]
int d = r.ints(1000, (2112 + 1)).findFirst().getAsInt();
// d will get a random value in the range [1,3]
int e = r.ints(-1, (5 + 1)).findFirst().getAsInt();
// e will get a random value in the range [1,3]
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
}
output: