Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Which of the following is a valid way to initialize an array in Java? A ) int [ ] numbers = 1 , 2 ,

Which of the following is a valid way to initialize an array in Java?
A) int[] numbers =1,2,3,4;
B) int[] numbers = new int [4]{1,2,3,4};
C) int numbers []= new int []{1,2,3,4};
D) All are not valid
What will be the output of the following code?
[][] arr ={{1,2,3},{4,5},{6,7,8,9}};
System.out.println(arr[1].length);
A)2
B)3
C)4
D)5
23. What will be the output of the following code?
int [] arr ={1,2,3,4,5};
System.out.println(arr[arr.length -2]);
A)1
B)4
C)5
D) ArrayIndexOutOfBoundsException
24. Which of the following will correctly iterate through all elements of a 2D array? [][] arr ={{1,2},{3,4},{5,6}}
A) for (int i=0;i arr.length; i++ for (int j++ln(arr[i][j]);i=0;ii++j=0;jarr[i];j++
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions