Array-promo
Matrix-promo

Question

Print largest elements of each column of integer matrix.

				
					Enter size of integer matrix:
4
Enter Elements in matrix:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Elements in matrix:
1 2 3 4 
5 6 7 8 
9 10 11 12 
13 14 15 16 
The Highest value of Column 1 is=13
The Highest value of Column 2 is=14
The Highest value of Column 3 is=15
The Highest value of Column 4 is=16
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class LargestNumberInEachColumn
{
    public static void main()
    {
        int[ ][ ] arr;
        int size,max=0;
        int i,j;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter size of integer matrix:");
        size=sc.nextInt();
        arr=new int[size][size];
        System.out.println("Enter Elements in matrix:");
        for(i=0;i< size;i++)
        {
            for(j=0;j< size;j++)
            {
                arr[i][j]=sc.nextInt();
            }
        }
        System.out.println("Elements in matrix:");
        for(i=0;i< size;i++)
        {
            for(j=0;j< size;j++)
            {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        for(j=0;j< size;j++)
        {
            max=arr[0][j];
            for(i=0;i< size;i++)
            {
                if(arr[i][j]>max)
                {
                    max=arr[i][j];
                }
            }
            System.out.println("The Highest value of Column "+(j+1)+" is="+max);

        }
    }
}



				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *