13.1] Write a program to display array element using for-each loop.
class arr { public static void main(String args[]) { int[] array={1,2,3,4}; for(int a: array) { System.out.println(a); } } } Output:
13.2] Write a program to implement multidimensional array. import java.util.*; class mda { public static void main(String args[]) { int [][] a =new int[3][3]; int [][] b =new int[3][3]; int [][] c =new int[3][3]; int i=0,j=0;
Scanner s = new Scanner(System.in);
System.out.println("Enter your first matrix :" ); for(i=0;i<3;i++) { for(j=0;j<3;j++) {
a[i][j] = s.nextInt();
} }
System.out.println("Enter your second matrix :"); for(i=0;i<3;i++) { for(j=0;j<3;j++) {
b[i][j] = s.nextInt(); } }
System.out.println("Matrix 1: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) {
System.out.print(a[i][j]+" ");
} System.out.println(" "); }
System.out.println("Matrix 2: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) {
System.out.print(b[i][j]+" ");
} System.out.println(" "); }
System.out.println("Addition of matrix :"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j] = a[i][j]+b[i][j]; System.out.print(c[i][j]+" ");
} System.out.println(" "); } } }
Output: