Instruction: Create a java program that generates elements (randomly from 10 - 75) of a 2-dimensional array (5x5) using the Random Class then perform the following: 1) Output the array elements 2) Output the sum of prime numbers in the array 3) Output the elements in the main diagonal. 4) Output the sum of the elements below the diagonal. 5) Output the sum of the elements above the diagonal. 6) Output the odd numbers below the diagonal. 7) Output the even numbers above the diagonal. Sample Input/Output: Depicted below are sample outputs when the program is executed (the items in bold characters are input from the user, while the items in bold italic are generated, calculated and printed by the program):

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

use two dimensional array and put comment on what each line of code does

PART 2: TwO-DIMENSIONAL ÅRRAY
Instruction:
Create a java program that generates elements (randomly from 10 – 75) of a 2-dimensional array
(5x5) using the Random Class then perform the following:
1) Output the
2) Output the sum of prime numbers in the array
3) Output the elements in the main diagonal.
4) Output the sum of the elements below the diagonal.
5) Output the sum of the elements above the diagonal.
6) Output the odd numbers below the diagonal.
7) Output the even numbers above the diagonal.
array
elements
Sample Input/Output:
Depicted below are sample outputs when the program is executed (the items in bold
characters are input from the user, while the items in bold italic are generated,
calculated and printed by the program):
Transcribed Image Text:PART 2: TwO-DIMENSIONAL ÅRRAY Instruction: Create a java program that generates elements (randomly from 10 – 75) of a 2-dimensional array (5x5) using the Random Class then perform the following: 1) Output the 2) Output the sum of prime numbers in the array 3) Output the elements in the main diagonal. 4) Output the sum of the elements below the diagonal. 5) Output the sum of the elements above the diagonal. 6) Output the odd numbers below the diagonal. 7) Output the even numbers above the diagonal. array elements Sample Input/Output: Depicted below are sample outputs when the program is executed (the items in bold characters are input from the user, while the items in bold italic are generated, calculated and printed by the program):
1) Output the array elements
33
21
30
45
32
50
10
50
35
42
25
12
35
12
11
45
14
50
28
21
15
41
15
19
41
2) Output the sum of prime numbers in the array.
112
3) Output the elements in the main diagonal.
21 10 35 28 41
4) Output the sum of the elements below the diagonal.
286
5) Output the sum of the elements above the diagonal.
311
6) Output the odd numbers below the diagonal.
25 45 15 41 19
7) Output the even numbers above the diagonal.
30 32 50 42 12
Required: The java file (FamilyName_2Dim.java) containing the code and 2 image files
(Samplel and Sample2) containing different sample input/output of the program.
Transcribed Image Text:1) Output the array elements 33 21 30 45 32 50 10 50 35 42 25 12 35 12 11 45 14 50 28 21 15 41 15 19 41 2) Output the sum of prime numbers in the array. 112 3) Output the elements in the main diagonal. 21 10 35 28 41 4) Output the sum of the elements below the diagonal. 286 5) Output the sum of the elements above the diagonal. 311 6) Output the odd numbers below the diagonal. 25 45 15 41 19 7) Output the even numbers above the diagonal. 30 32 50 42 12 Required: The java file (FamilyName_2Dim.java) containing the code and 2 image files (Samplel and Sample2) containing different sample input/output of the program.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

please put comments on these line of codes of what these do:

private static void evenNumbersAboveDiagonal(int[][] arr) {
for(int j=1;j<5;j++){
for(int i=j-1;i>=0;i--){
if(arr[i][j]%2 == 0)
System.out.print(arr[i][j] + " ");
}
}
System.out.println();
}

private static void oddNumbersBelowDiagonal(int[][] arr) {
for(int i=0;i<5;i++){
for(int j=0;i>j;j++){
if(arr[i][j]%2==1)
System.out.print(arr[i][j] + " ");
}
}
System.out.println();
}

private static int sumOfElementsAboveDiagonal(int[][] arr) {
int sum = 0;
for (int j=1;j<5;j++) {
for (int i=j-1;i>=0;i--) {
sum += arr[i][j];
}
}
return sum;
}

private static int sumOfElementsBelowDiagonal(int[][] arr) {
int sum = 0;
for(int i=0;i<5;i++){
for(int j=0;i>j;j++) {
sum += arr[i][j];
}
}
return sum;
}

private static void elementsOfMainDiagonal(int[][] arr) {
for (int i=0;i<5;i++) {
for (int j=0; j<5;j++) {
if(i == j)
System.out.print(arr[i][j] + " ");
}
}
System.out.println();
}

private static int sumOfPrime(int[][] arr) {
int sum = 0;
for(int i=0;i<5;i++){
for(int j=0;j<5;j++) {
if(isPrime(arr[i][j]))
sum+=arr[i][j];
}
}
return sum;
}

private static boolean isPrime(int n){
if(n<=1)
return false;
for(int i=2;i<n;i++)
if(n%i == 0)
return false;
return true;
}
}

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY