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

java sub- array

DJJONES91
DJJONES91 


Create a 2-dimensional array; have the row size and the column size declared as class constants. Your program should use subarray processing and modularity. Have methods to: Fill a 2-dimensional array with random numbers (range MIN-MAX, declared as class constants MIN = -10 and MAX = 50). Return true if all the elements of a 2-dimensional array are positive and false otherwise (Boolean method, named allPositive). This method should be invoked first for the entire table and next, repeatedly, in a loop, for subarrays of the original table. Consider first how many parameters have to be passed. Print a 2-dimensional array; invoke it first to display the original table and invoke it again after each method call to allPositive to display the subarray checked. Again, consider first how many parameters have to be passed. Generate output similar to the sample output below. SAMPLE RUN: The original table is: 19 30 9 37 12 47 4 -1 45 33 15 20 25 4 22 35 12 -8 -6 -2 27 50 2 2 47 0 -3 30 45 9 32 49 30 50 -10 36 35 40 -1 43 23 29 -2 -3 29 5 48 3 -3 25 16 -10 23 30 12 24 18 15 16 33 26 2 41 41 20 12 -10 21 -2 12 50 -7 -6 48 0 11 10 19 14 2 35 43 3 20 -5 14 -6 49 -8 33 -8 6 26 -4 39 21 13 46 44 2 22 45 40 41 30 -5 -3 28 17 21 25 40 27 33 26 -1 -5 -4 46 -9 30 24 47 -9 26 10 35 27 6 3 -10 9 14 4 19 31 32 32 -9 5 -7 27 14 -2 41 8 30 5 17 48 24 45 11 36 -7 27 50 48 48 46 -3 21 32 3 -4 1 33 -6 37 -8 -4 2 -4 -10 40 14 18 41 48 46 25 25 7 4 -9 26 9 -6 47 33 34 26 29 1 10 19 9 41 5 45 41 9 -6 35 13 4 -3 -4 25 -10 35 10 -7 16 8 -1 5 44 15 12 26 4 12 13 27 -1 5 29 34 11 38 30 27 10 33 26 27 31 38 -5 19 32 -3 48 19 20 -1 39 24 24 37 13 14 24 13 41 9 13 -5 41 17 12 37 -1 2 23 7 28 -8 19 4 19 26 9 35 -6 -8 43 33 35 18 2 8 11 -2 10 32 23 -9 9 7 40 48 13 0 -3 35 15 10 31 Some elements in the original table are negative. Do you want to start subarray processing(Y/N): y How many rows: -8 ERROR! Should be positive and < 15. REENTER: 5 How many columns: -3 ERROR! Should be positive and < 20. REENTER: 6 The subarray is: 19 30 9 37 12 47 27 50 2 2 47 0 23 29 -2 -3 29 5 26 2 41 41 20 12 35 43 3 20 -5 14 Some elements in this subarray are negative. Do you want to continue subarray processing(Y/N): y How many rows: 2 How many columns: 6 The subarray is: 19 30 9 37 12 47 27 50 2 2 47 0 All elements in this subarray are positive. Do you want to continue subarray processing(Y/N): y How many rows: 5 How many columns: 2 The subarray is: 19 30 27 50 23 29 26 2 35 43 All elements in this subarray are positive. Do you want to continue subarray processing(Y/N): n Attachments
Tags
Clarifications

Answers

JAVA SubArray Solution

Seeker
Seeker 



...is attached Attachments
SubArrays.java (2 K) Download Preview
to start(Y/N): "); String ch = s.nextLine(); if(ch.equalsIgnoreCase("y")){ array = new int[ROWS][COLUMNS]; fill(); print(); checkForNegatives(); } } private static void checkForNegatives(){ negativeExists = false; for(int i=0;i<array.length;i++) { for(int j=0;j<array[i].length;j++){ if(array[i][j] < 0){

Screenshots
Purchase Answer