From 7eed10e420c669cdafe134e3f1d21eea2221b2c7 Mon Sep 17 00:00:00 2001 From: ravi413 Date: Sun, 3 Oct 2021 17:29:47 +0530 Subject: [PATCH] Create implementation of 2D array in java --- implementation of 2D array in java | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 implementation of 2D array in java diff --git a/implementation of 2D array in java b/implementation of 2D array in java new file mode 100644 index 0000000..4133a2d --- /dev/null +++ b/implementation of 2D array in java @@ -0,0 +1,65 @@ +;package practice; +import java.util.Scanner; + +public class twoDsummation { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner s = new Scanner(System.in); + + int a[][] = new int[2][3]; + int b[][] = new int[2][3]; + int c[][] = new int[2][3]; + + System.out.println("enter first array "); + + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + a[i][j]= s.nextInt(); + } + } + + + System.out.println("enter second array "); + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + b[i][j]= s.nextInt(); + } + } + System.out.println("first array is: "); + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + System.out.print(a[i][j]); + System.out.print(" "); + } + System.out.println("\n"); + } + + System.out.println("second array is: "); + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + System.out.print(b[i][j]); + System.out.print(" "); + } + System.out.println("\n"); + } + + System.out.println("sum of array a[][] and b[][]"); + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + c[i][j]= a[i][j]+b[i][j]; + } + } + + for(int i=0;i<2;i++) { + for(int j=0;j<3;j++) { + System.out.print(c[i][j]); + System.out.print(" "); + } + System.out.println("\n"); + } + + + } + +}