Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

java 2-dim array

DJJONES91
DJJONES91 


2. Create a 2-dimensional array; get the row size and the column size of the array as input from the user (validate input). Your program should use modularity. Have methods to: Fill a 2-dimensional array with random numbers (range MIN - MAX, declared as class constants MIN = 1 and MAX = 50). Print a 2-dimensional array. Calculate the average of each column and write it in a 1-dimensional array. Print a 1-dimensional array (call it for the resulting average/column array). Generate output similar to the sample output below. SAMPLE RUN: Do you want to start(Y/N): y Enter row size: -4 ERROR! Should be positive. REENTER: 4 Enter column size: -8 ERROR! Should be positive. REENTER: 8 The original table is: 22 16 41 12 39 39 10 31 14 39 26 41 40 23 5 8 1 2 49 41 8 30 33 2 11 23 21 48 14 7 19 19 The average/each column: 12.00 20.00 34.25 35.50 25.25 24.75 16.75 15.00 Do you want to continue(Y/N): y Enter row size: 5 Enter column size: 9 The original table is: 16 20 27 23 21 38 45 7 17 44 50 34 22 41 15 27 25 36 7 35 4 42 39 26 3 15 7 11 13 22 18 49 41 30 50 3 19 33 41 6 39 45 20 6 39 The average/each column: 19.40 30.20 25.60 22.20 37.80 33.00 25.00 20.60 20.40 Do you want to continue(Y/N): n Attachments
Tags
Clarifications

Answers

JAVA 2-Dimensional Array Solution

Seeker
Seeker 



...is attached Attachments
TwoDimensionalArray.java (2 K) Download Preview
private static int row; private static int column; public static void main(String args[]) { Scanner s = new Scanner(System.in); System.out.print("Do you want to start(Y/N): "); String ch = s.nextLine(); while(ch.equals("y") || ch.equals("Y")) { System.out.print("\nEnter row size: "); row =

Screenshots
Purchase Answer

java 2-Dim array solution

coderTony
coderTony 



commented lines to... Attachments
TwoDimArray.java (3 K) Download Preview
false; } return validBool; } //use the row and column inputs to fill the array private static Integer[][] Fill2D_Random(int row, int col) { Integer[][] inArr = new Integer[row][col]; Random rand = new Random(); for (Integer[] obj1 : inArr) { for

TwoDimArray.java (3 K) Download Preview
i < obj1.length; i++) { obj1[i] = randomMIN + rand.nextInt(randomMAX + 1); } } return inArr; } //Print a 2-Dimensional array private static void print2D(Integer[][] inArr) { for (Integer[] obj1 : inArr) { print1D(obj1); } }

TwoDimArray.java (3 K) Download Preview
private static void print1D(Integer[] inArr) { String tmpLine = ""; for (int itm : inArr) { tmpLine = tmpLine + Integer.toString(itm) + " "; } System.out.println(tmpLine); } //Print a 1-Dimensional array (Double) private static void print1D_AVG(Double[] inArr) { String

Screenshots
Purchase Answer