[Solved] Expected Write Program Scratch Program Array Initialized 23 Random Integers 1000 1999 Incl Q37298549
You are expected to write a program from scratch. In theprogram, an array will be initialized with 23 random integersbetween 1000 and 1999 (inclusive). The output of the program is 4lines on the screen, specifically,
- All elements in the array (line 1)
- All elements in reverse order (line 2)
- Every element that is less than 1500 and also at an odd index(line 3)
- Every odd element that is larger than 1500 (line 4)
Note that you have to use the method Math.random() we coveredpreviously to generate the random numbers. Other ways like usingRandom class we haven’t covered or just reading in 23 numbers fromkeyboards are NOT accepted.
Please submit 1) Java source code (.java file), and 2)screenshot of jGRASP window where the expected output is shown, toBlackboard.
————————————————————————
import java.util.Arrays;public class Programming3{ public static void main(String[] args) { int [] randomArr = new int [23]; for(int i=0; i < randomArr.length; i++) { randomArr[i] = (int) (Math.random() * 1000) + 1000; } // Output the array System.out.print(“Array: “); for (int elem : randomArr) { System.out.print(elem + ” “); } System.out.println(“”); // Reverse output System.out.print(“Reverse: “); for (int i = randomArr.length-1; i >= 0; i–) { System.out.print(randomArr[i] + ” “); } System.out.println(“”); //Line 3: Every element <1500 and at an odd index System.out.print(“<1500 & odd index: “); for (int i = 0; i <= randomArr.length-1; i++) { if (randomArr[i] < 1500 && i%2 == 1) { System.out.print(randomArr[i] + ” “); } } System.out.println(“”); //Line 4: Every odd element > 1500 System.out.print(“>1500 & odd: “); for (int i = 0; i <= randomArr.length-1; i++) { if (randomArr[i] > 1500 && randomArr[i]%2 == 1) { System.out.print(randomArr[i] + ” “); } } }}
Expert Answer
Answer to You are expected to write a program from scratch. In the program, an array will be initialized with 23 random integers b… . . .
OR

