Questions and CORRECT Answers
Which of the following correctly defines and instantiates an array that can store 30 integers? -
CORRECT ANSWER - int[] array = new int[30];
What is output by the code below?
int[] array = {33,14,37,11,27,4,6,2,6,7}; System.out.println(array.length); - CORRECT
ANSWER - 10
What is output by the code below?
int[] array = {7,8,10,11,4,3};
array[array[0]/2]=15;
array[array[4]+1]=9;
array[array.length/3+2]=5;
array[1]=array[0]+4;
System.out.println(array[4]); - CORRECT ANSWER -6
What is output by the code below?
int[] array = {5,10,3,6,9,15};
,for(int i=0; i<array.length/2; i=i+2)
{
array[i]=array[array.length-i-2];
}
System.out.println(array[0]); - CORRECT ANSWER -9
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[ray.length-2]); - CORRECT ANSWER - 234
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[3].substring(0,2) + ray[4].charAt(1)); - CORRECT ANSWER - 237
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[1].charAt(2)); - CORRECT ANSWER -e
, What is output by the code below?
int[] nums = new int[10];
for (int i=0; i < nums.length; i++)
{
nums[i] = i*2;
}
System.out.println(nums[9]); - CORRECT ANSWER - 18
What is returned by method bot given the call shown below?
//client code in the runner or main method
int[] sRay = {9,9,7,1,2,3,4,5,6,2,2,3,7,3};
System.out.println( bot(sRay) );
//method bot
public static int bot( int[] ray )
{