Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me recreate the given codes below in java, without using methods, which is currently the one that was used in these given set

Please help me recreate the given codes below in java, without using methods, which is currently the one that was used in these given set of codes.

import java.util.Random; public class twodimarray { public static void main(String[] args) { int[][] a=new int[5][5]; twodarray(a, 10, 50); System.out.println("1.) Output the Array Elements"); printElements(a); System.out.println(); System.out.println("2.) Output the sum of prime numbers in array."); sumPrime(a); System.out.println(); System.out.println("3.) Output the elements in main diagonal."); mainDiagonal(a); System.out.println(); System.out.println("4.) Output the sum of the elements below diagonal."); sumBelowDiagonal(a); System.out.println(); System.out.println("5.) Output the sum of the elements above diagonal."); sumAboveDiagonal(a); System.out.println(); System.out.println("6.) Output the odd numbers below diagonal."); oddBelowDiagonal(a); System.out.println(); System.out.println("7.) Output the even numbers above diagonal."); evenAboveDiagonal(a); System.out.println(); } static void twodarray(int[][] a,int min,int max) { Random rand = new Random(); for(int i=0;ij) { sum+=a[i][j]; } } System.out.println(sum); } static void sumAboveDiagonal(int[][] a) { int sum=0; for(int i=0;ij && a[i][j]%2==1) { System.out.printf("%2d\t",a[i][j]); } } System.out.println(); } static void evenAboveDiagonal(int[][] a) { for(int i=0;i

image text in transcribed

Instruction: Create a java program that generates elements (randomly from 10 - 50) 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): 1) Output the array elements 21 30 33 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions