Java Practice exam 2025 Questions
and Answers
Which of the following correctly defines and instantiates an array that can store 30
integers? - 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); - 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]); - 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]); - ANSWER✔✔-9
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[ray.length-2]); - 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)); - ANSWER✔✔-237
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
, System.out.println(ray[1].charAt(2)); - 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]); - ANSWER✔✔-18
What is returned by method bot given the call shown below?
//client code in the runner or main method
and Answers
Which of the following correctly defines and instantiates an array that can store 30
integers? - 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); - 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]); - 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]); - ANSWER✔✔-9
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
System.out.println(ray[ray.length-2]); - 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)); - ANSWER✔✔-237
What is output by the code below?
String[] ray = {"abc","ade","123","234","678"};
, System.out.println(ray[1].charAt(2)); - 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]); - ANSWER✔✔-18
What is returned by method bot given the call shown below?
//client code in the runner or main method