Computer Science, asked by swaranava10mymail, 6 months ago

WAP in Java to enter numbers in 3x3 matrix and display the sum of left diagonal and right diagonal.

Answers

Answered by udayagrawal49
2

Answer: The required Java program is: (I have used the simplest method)

import java.util.Scanner;

public class Matrix {

public static void main(String[] args) {

 Scanner scan = new Scanner(System.in);

 int a11 = scan.nextInt();

 int a12 = scan.nextInt();

 int a13 = scan.nextInt();

 int a21 = scan.nextInt();

 int a22 = scan.nextInt();

 int a23 = scan.nextInt();

 int a31 = scan.nextInt();

 int a32 = scan.nextInt();

 int a33 = scan.nextInt();

 scan.close();

 System.out.println("The given matrix is :");

 System.out.println(a11+" "+a12+" "+a13+"\n"+a21+" "+a22+" "+a23+"\n"+a31+" "+a32+" "+a33);

 int sumL = a11+a22+a33;

 int sumR = a13+a22+a31;

 System.out.println("Sum of elements of left diagonal is "+sumL);

 System.out.println("Sum of elements of right diagonal is "+sumR);

}

}

Please mark it as Brainliest.

Similar questions