Double Dimensional Array(Matrix) Program I (Maximum minimum element, sum, average)
Double Dimensional Array(Matrix) Program I…: solved Java program for ISC Class 11 Computer Science with complete BlueJ code, explanation and sample output.
Write a program to ask the user to input a double dimensional integer array and print the biggest(Maximum) and the smallest(Minimum) element of the array with its place in the array. Print the sum and the average of all the elements also.
import java.io.*;
class MinMaxDDA{
public static void main() throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter no. of rows");
int r=Integer.parseInt(br.readLine());
System.out.println("Enter no. of columns");
int c=Integer.parseInt(br.readLine());
int m[][]=new int[c][r];
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){
System.out.println("Enter value for matrix");
m[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println("the matrix is:");
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){
System.out.print(m[i][j]+" ");
}
System.out.println();
}
int x=m[0][0];
int y=m[0][0];
int r1=0,c1=0,r2=0,c2=0;
int sum=0;double avg=0.0;
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){sum+=m[i][j];
if(m[i][j]<x){
x=m[i][j];
r1=i;
c1=j;
}
else if(m[i][j]>y){
y=m[i][j];
r2=i;
c2=j;
}
}
}
avg=sum/(c*r);
System.out.println("The max value in matrix is "+y);
System.out.println("It is at"+r2 +" "+c2 +" index ");
System.out.println("The min value in matrix is "+x);
System.out.println("It is at"+r1 +" "+c1 +" index ");
System.out.println("The sum of all the elements is "+sum);
System.out.println("The average of the matrix is "+avg);
}
}
Output:Output:
Enter no. of rows
3
Enter no. of columns
3
Enter value for matrix
8
Enter value for matrix
7
Enter value for matrix
6
Enter value for matrix
4
Enter value for matrix
5
Enter value for matrix
3
Enter value for matrix
2
Enter value for matrix
1
Enter value for matrix
9
the matrix is:
8 7 6
4 5 3
2 1 9
The max value in matrix is 9
It is at 2 2 index
The min value in matrix is 1
It is at 2 1 index
The sum of all the elements is 45
The average of the matrix is 5.0
Related Posts
Continue learning with these related articles

ISC Practical 2027: Image Editor – Brighten an Image and Find Bright Spots (2-D Array) – Java Program
Fully solved ISC Computer Science Practical 2027 2-D array question: brighten a grayscale image (capping values at 255) and find the bright spots, pixels larger than all four neighbours. Includes a missing bright spot in CISCE’s sample output.

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.