LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
8 views
in Information Technology by (48.1k points)
closed by
 Which of the following Java statements declare and allocate a 2-dimensional array of integers with four rows and five columns? 
1. int array [4][5];  
2. int array [][] = new int [4][5]
3. int array [5][4]; 
4. int array [][]= new int [5][4] 

1 Answer

0 votes
by (35.4k points)
selected by
 
Best answer
Correct Answer - Option 2 : int array [][] = new int [4][5]

Concept:

Java is a high-level programming language developed by sun microsystems. Java is platform-independent, simple, portable, object-oriented, and secured language. In java, an array is an object which contains a similar type of element.

Explanation:

Elements of an array are stored in contiguous memory locations. A fixed set of elements can be stored in java array. An array is an object of dynamically generated classes in java. We can also declare anonymous arrays in java. 

Two types of an array are single dimensional and multidimensional.

Single dimensional array syntax: 

dataType []arr;          OR

dataType arr[];

Multidimensional array: in this data is stored in the form of rows and columns. 

We can initialize the array in java as : 

int[][] array = new int [] [];        OR

int array[][] = new int [][];

Here, in this question we have to allocate 2-d array of integers with 4 rows and 5 columns.It will be: 

int array[][] = new int [4][5];

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...