1.Write a method that takes two integer number as a parameters such as M and N. This method should return a table with random numbers with the size of MxN. 2.Write an another method that take a table as a parameter and prints out table contents as appear in a table. 3.Write one more method that takes one table and one boolean as parameters. If this boolean variable is set to “true” this method returns the maximum number in the table, other case returns the minimum number. 4.Test these method with different numbers. #java
1. int method(int a,int b) { int matrix[a,b] for(i=0;i<a;i++) { for(j=0;j<b;j++) printf("%d", a[i,j];}}} convert it into java using class
I wrote 1 and 2question but i can't do the third one. public static int[][] numberToArray(int m, int n){ int[][] array=new int[m][n]; Random r=new Random(); //int number=r.nextInt(100); for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ int number=r.nextInt(100); array[i][j]=number; System.out.print(array[i][j]+", "); } System.out.println(" "); } return array; } //Second question public static void print(int [][] array){ for(int i=0; i<array.length; i++){ for(int j=0; j<array[0].length; j++){ System.out.print(array[i][j]+" "); } System.out.println(" "); } }
how can i do the 3. question
private int getMinMax(int[][] table, boolean max){ if(max) return max(table); else return min(table); } private int min(int[][] table){ int tempMin = int[0][0]; for(int i = 0; i < table.length; i++) for(int j = 1; j < table[i].length; j++) if(table[i][j] < tempMin) tempMin = table[i][j]; return tempMin; } private int max(int[][] table){ int tempMax = int[0][0]; for(int i = 0; i < table.length; i++) for(int j = 1; j < table[i].length; j++) if(table[i][j] > tempMax) tempMax = table[i][j]; return tempMax; } //or private int getMinMax(int[][] table, boolean max){ if(max) return max(table); else return min(table); } private int min(int[][] table){ int tempMin = int[0][0]; for(int i = 0; i < table.length; i++) for(int j = 1; j < table[i].length; j++) if(table[i][j] < tempMin) tempMin = table[i][j]; return tempMin; } private int max(int[][] table){ int tempMax = int[0][0]; for(int i = 0; i < table.length; i++) for(int j = 1; j < table[i].length; j++) if(table[i][j] > tempMax) tempMax = table[i][j]; return tempMax; }
THANKS
?
What do you believe the answer is?
Join our real-time social learning platform and learn together with your friends!