Advertisements
Advertisements
Question
Write a program for the following.
Fill a double dimensional array of order 4 × 4. Print the largest element of the left diagonal.
[The left diagonal is from left top to right bottom]
Code Writing
Advertisements
Solution
importjava.util.*;
class Q4
{
public void main()
{
int RC[][] = new int [4][4];
int r = 0, c = 0, max = 0;
Scanner sc = new Scanner(System.in);
for(r = 0; r<4; r++)
{
for(c = 0; c<4; c++)
{
System.out.print(" Enter value for cell number "+r+""+c+":: ");
RC[r][c] = sc.nextInt();
}
}
max = RC[0][0];
for(r = 0; r <4; r++)
{
if(RC[r][r]> max)
{
max = RC[r][r];
}
}
System.out.print(" Largest element = "+ max);
}
}shaalaa.com
Is there an error in this question or solution?
Chapter 9: Arrays - Double Dimension - Exercises
