Java Practice exam UPDATED ACTUAL Exam Questions and
CORRECT Answers
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]); - 9
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[ray.length-2]); - 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)); - 237
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[1].charAt(2)); - 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]); - 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 )
{
int stuff = 0;
for(int i = 0; i<ray.length; i++)
if(ray[i] % 2 == 0)
stuff = stuff + ray[i];
return stuff;
} - 16
What is output by the code below?
int t = 1, amount = 0;
do{
amount = amount = 2;
t = t + 2;
CORRECT Answers
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]); - 9
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[ray.length-2]); - 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)); - 237
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[1].charAt(2)); - 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]); - 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 )
{
int stuff = 0;
for(int i = 0; i<ray.length; i++)
if(ray[i] % 2 == 0)
stuff = stuff + ray[i];
return stuff;
} - 16
What is output by the code below?
int t = 1, amount = 0;
do{
amount = amount = 2;
t = t + 2;