Create 2-D array say m : ask the user to input row and column sizes from keyboar
ID: 664204 • Letter: C
Question
Create 2-D array say m :
ask the user to input row and column sizes from keyboard (use Scanner)
Assuming that the last digit of your panth number is N, if the user input column size is bigger than N+5 ask the user to reinput the column size
fill all arrays elements as double numbers in the range of (4.0 , 11.0) by using of random object
pass the above array m and call the following two methods
findMaxCol(m)
returnAvg(m)
print out the avg of array m
In findMaxCol(double[][]array), find and print the largest sum of columns in the 2 d array
in returnAvg(double[][] array find the average of all elements in the array and return the average
Explanation / Answer
here is the sample code
---------------------------------------------
public class InputArray{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Input number of row : ");
int row = s.nextInt();
System.out.print("Input number of column : ");
int column = s.nextInt();
if (column > row+5)
{
System.out.print("Invalid input!! Enter number of column again : ");
int column = s.nextInt();
}
int [][] array1 = new int[row][column];
double start = 4.0;
double end = 11.0;
for (int i = 0; i < row; i++)
{
for(int j = 0; j < column; j++) {
double random = new Random().nextDouble();
array1[i][j] = start + (random * (end - start));
}
}
findMaxCol(double[][]array){
double total = 0;
double max = 0;
for(int column = 0; column < max; column++){
total = 0;
array1[row][column] = (int)(Math.random() * 100);
if(column < array1[row].length);
total += array1[row][column];
System.out.println("Column " + column + " total: " + total);
}
returnAvg(double[][] array1){
double sum = 0.0;
for (int i = 0; i < array1.length; i++) {
for (int j = 0; j < a[i].length; j++) {
sum += a[i][j];
}
}