import java.util.Scanner; class MatrixSum { public static void main(string args[]) { Scanner sc=new.Sacnner(System.in); int a[][]=new.int[3][3]; System.out.println("enter the values"); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { a[i][j]=sc.nextInt(); } } int sum=0; for(int x[]:a) { for(int y:x) { sum+=y; } } System.out.println("sum="+sum); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter