Question

In: Computer Science

java please 1. Write a Java program to generate random numbers in the following range a....

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 )

Solutions

Expert Solution

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:


Related Solutions

Write a Java program to generate random numbers in the following range a. 1 <=n <=...
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 JAVA PROGRAMMING
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1...
JAVA PROGRAM Write program that will prompt user generate two random integers with values from 1 to 10 then subtract the second integer from the first integer. Note, if the second integer is greater than the first integer, swap the two integers before making the subtraction.Then prompt user for the answer after the subtraction. If the answer is correct, display “Correct”otherwise display “Wrong”.You will need to do this in a loop FIVE times and keep a count of how many...
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
Write a Java program that implements the Number Guessing Game: 1. First generate a random number...
Write a Java program that implements the Number Guessing Game: 1. First generate a random number (int) between 0 and 100, call it N 2. Read user input (a guess) 3. check the number, if it's smaller than N, output "The number is larger than that" 4. If the input is larger than N, output "The number is smaller than that" 5. If the input is equal to N, output " You got it!", and exit 6. Repeat until the...
Write a simple java program to list roman numeral for a given range of numbers. Roman...
Write a simple java program to list roman numeral for a given range of numbers. Roman numerals are represented by seven different symbols: I, V, X, L, C, D, and M. I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000 Roman numerals are usually written largest to smallest from left to right. But a number like 4 is not written as IIII. It is written as IV. Because...
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the reverse order. Using a ListItreator output the contents of the LinkedList in the original order.
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the original order. Using a ListItreator output the contents of the LinkedList in the reverse order.
For this problem, you will write a program using two queues. Generate n random numbers between...
For this problem, you will write a program using two queues. Generate n random numbers between 10 and 100 (both inclusive), where n>9. The value of n should be taken as input from the user and n should be >9. The numbers could be duplicated. Enqueue all these numbers to the first queue. The objective is to find the numbers whose sum of digits is odd and enqueue them to the second queue. The remaining numbers (whose sum of digits...
Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT