Array-promo
Matrix-promo

Question

Print elements below the right diagonal of the integer matrix.

				
					Enter size of Matrix:
4
Enter Elements in Matrix:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Original Matrix:
1 2 3 4 
5 6 7 8 
9 10 11 12 
13 14 15 16 
elements Below right Diagonal Matrix:
        
      8 
    11 12 
  14 15 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 BelowRightDiagonal
{
    public static void main()
    {
        int[ ][ ] arr;
        int m;
        int i,j;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter size of Matrix:");
        m=sc.nextInt();        
        arr=new int[m][m];
        System.out.println("Enter Elements in Matrix:");
        for(i=0;i< m;i++)
        {
            for(j=0;j< m;j++)
            {
                arr[i][j]=sc.nextInt();
            }
        }
        System.out.println("Original Matrix:");
        for(i=0;i< m;i++)
        {
            for(j=0;j< m;j++)
            {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }

        System.out.println("elements Below right Diagonal Matrix:");
        for(i=0;i< m;i++)
        {
            for(j=0;j< m;j++)
            {
                if(j>(m-i-1))
                {
                    System.out.print(arr[i][j]+" "); 
                }
                else
                {
                    System.out.print("  ");
                }

            }
            System.out.println();
        }
    }
}


				
			

Coding Store

Leave a Reply

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