From 724345c9f7d40c864bdd5df5b0585b47521f2fe2 Mon Sep 17 00:00:00 2001 From: Bhushan Pakhle Date: Thu, 13 Oct 2022 15:18:22 +0530 Subject: [PATCH] Create 2D_Array_Creation.java This java file contains the code for creation of 2D Array in java. --- 2D_Array_Creation.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2D_Array_Creation.java diff --git a/2D_Array_Creation.java b/2D_Array_Creation.java new file mode 100644 index 0000000..22f747b --- /dev/null +++ b/2D_Array_Creation.java @@ -0,0 +1,32 @@ + +import java.util.Scanner; + +public class ArrayCreation2D { + public ArrayCreation2D() { + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the no. of rows and columns: "); + int nr = sc.nextInt(); + int nc = sc.nextInt(); + int[][] b = new int[nr][nc]; + + int i; + int j; + for(i = 0; i < nr; ++i) { + for(j = 0; j < nc; ++j) { + b[i][j] = sc.nextInt(); + } + } + + System.out.println("The elements are"); + + for(i = 0; i < nr; ++i) { + for(j = 0; j < nc; ++j) { + System.out.println(b[i][j]); + } + } + + } +}