MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Create an array of 12 strings called months.
A
String[] months = new String[12];
B
String months = new String[12];
C
String[] months = new String[];
D
String[12] months = new String[];
Explanation: 

Detailed explanation-1: -Initialization: months = new Month[12]; This creates an array of 12 Month references.

Detailed explanation-2: -You can also initialize the String Array as follows: String[] strArray = new String[3]; strArray[0] = “one”; strArray[1] = “two”; strArray[2] = “three”; Here the String Array is declared first. Then in the next line, the individual elements are assigned values.

Detailed explanation-3: -The elements of array InputData are INTEGERs and the indices are in the range of 0 and 100.

Detailed explanation-4: -We cannot print array elements directly in Java, you need to use Arrays. toString() or Arrays. deepToString() to print array elements. Use toString() method if you want to print a one-dimensional array and use deepToString() method if you want to print a two-dimensional or 3-dimensional array etc.

There is 1 question to complete.