How to create a 2-D array in java

0 votes
I cannot find a simplest syntax for 2-D array which I can understand easily. if  can get the apt solution?
Apr 13, 2018 in Java by sophia
• 1,400 points
1,533 views

2 answers to this question.

0 votes
You can refer the following code to create 2D array:

class 2D_array

 {

public static void main (String args[])

 {

    int arr[][]=new int[3][3];

   System.out.println("Enter the elements");

   for(int i=0;i<arr.length;i++)

           {

                 for(int j=0;j<arr[i].length;j++)

                        {

                            Scanner sc=new Scanner(System.in);

                            arr[i][j]=sc.nextInt();

                        }

           }

System.out.println("your array is");

for(int i=0;i<arr.length;i++)

{

for(int j=0;j<arr[i].length;j++)

    {

System.out.print(arr[i][j]+" ");

    }

System.out.println();

}
answered Apr 13, 2018 by Akrati
• 3,190 points
0 votes
int[][] multi = new int[5][];
multi[0] = new int[10];
multi[1] = new int[10];
multi[2] = new int[10];
multi[3] = new int[10];
multi[4] = new int[10];
answered Jul 16, 2018 by Daisy
• 8,140 points

Related Questions In Java

0 votes
1 answer

How to create a temporary directory/folder in java?

If you are using JDK 7 use ...READ MORE

answered Aug 28, 2018 in Java by Frankie
• 9,830 points
6,389 views
0 votes
1 answer

How to create a memory leak in Java?

Hello @kartik, A simple thing to do is ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,840 points
723 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,299 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
2,479 views
0 votes
1 answer

Deep copying a 2d array in Java

I guess, for deep copying you will ...READ MORE

answered Nov 13, 2018 in Java by code.reaper12
• 3,500 points
8,825 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,194 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,350 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,418 views
+1 vote
3 answers

How to convert a List to an Array in Java?

Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE

answered Aug 7, 2018 in Java by Akrati
• 3,190 points
1,127 views
0 votes
2 answers

How to convert array into list in Java?

Another workaround if you use apache commons-lang: int[] ...READ MORE

answered Aug 10, 2018 in Java by samarth295
• 2,220 points
879 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP