Oracle Java Foundation: Review Modul 6 - 9
Oracle Java Foundation: Review Modul 6 - 9
Oracle Java Foundation: Review Modul 6 - 9
REVIEW MODUL 6 - 9
LOOP
Given the code fragment:
Which option can replace xxx to enable the code to print 135?
A. int e = 0; e < = 4; e++
B. int e = 0; e < 5; e + = 2
C. int e = 1; e < = 5; e + = 1
D. int e = 1; e < 5; e+ =2
A. Replace line 6 with System, out. print (--x) ;
C. Compilation rails.
E. An ArraylndexOutOfBoundsException is thrown at
runtime.
A. [Robb, Rick, Bran]
B. [Robb, Rick]
B. 3 4 3 6
C. 5 4 5 6
D. 3 6 4 6
A. int[] array n= new int[2];
B. int[] array;
array = int[2];
B. A B C D Work done
C. A Work done
D. Compilation fails
A. 10 Hello World!
B. Hello Universe!
C. Hello World!
D. Compilation fails.
Which of the following are correct array declaration statements? (Select one or more options from
the list)
1. int numbers[] = new int[10];
2. int[] numbers = new int[20];
3. int numbers = new numbers[30];
4. int numbers = new int[10];
Which of the following are correct array initialization statements?
1. double[] doubles = new { 1.0d, 1.1d, 1.2d };
2. int[] numbers = new int[3] { 1, 2, 3 };
3. char[] letters = new char[] { 'A', 'B', 'C' };
4. String[] words = { "first", "second", "third" };
Select four ways to create an array which can be successfully compiled.
Keep in mind, the compilation stage is not the same as the running stage.
This task may need some experiments with code.
1. char[] array = new char[-1];
2. char[] array = new char[10000000000000];
3. char[] array = new char[1];
4. char[] array = new char[0];
5. char[] array = { 'a', 'b', 'c', 'd' };
What is the output of the code below?
int numbers[] = { 1, 2, 3, 4, 5 };
Arrays.fill(numbers, 1, 5, 10);
System.out.println(Arrays.toString(numbers));
1. [1, 2, 3, 4, 5]
2. [1, 10, 10, 10, 10]
3. ArrayIndexOutOfBoundsException
4. [10, 10, 10, 10, 10]
Given four arrays of integers:
int[] numbers1 = { 1, 2, 3, 4 };
int[] numbers2 = { 1, 2, 3, 4 };
int[] numbers3 = { 4, 3, 2, 1 };
int[] numbers4 = { 1, 2, 3 };
Select all invocations that return true.
1. Arrays.equals(numbers2, numbers3)
2. Arrays.equals(numbers1, numbers1)
3. Arrays.equals(numbers1, numbers4)
4. Arrays.equals(numbers3, numbers1)
5. Arrays.equals(numbers1, numbers2)
Given the following code:
int arr[] = new int[] { 0, 1, 1, 2, 3, 5, 8, 13, 21 };
int n = 6;
n = arr[arr[n] / 2];
Enter the value of n
QUESTION 1
You have a loop for calculating the sum of integer numbers in the range from start to end (inclusively). The result is
stored in the accumulator variable. Assume that start and end variables are already declared as some integer values,
so that start <= end.
int accumulator = 0; // (1)
for (int i = start; i <= end; i++) { // (2)
accumulator += i; // (3)
}
You need to change two lines in this code to calculate the multiplication of integer numbers in this range. Select the
correct revision.
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
QUESTION 5
What does this code print?
A. 02 468
B. 2 4 6 8 10
C. 0 2 4 6 8 10
D. 2 4 6 8 10
QUESTION 6
A. The continue statement can be used inside the for and while loops to skip
the current iteration.
B. The break statement can be used inside the for and while loops to exit the
loop.
C. The break and continue statements behave the same.
D. The break statement inside a nested for loop allows exit from this loop and
external loops.
QUESTION 7
How many times will the letter 'f' be printed?
QUESTION 16
Which of the following method declarations are syntactically correct and compliant with
the style recommendations?
A. int abs(int)
B. abs(int)
C. abs
D. int abs
QUESTION 20
What will happen in case when the main method is declared with syntactic correct but
not supported by JVM combinations of modifiers, returning value and parameters?
A. A class
B. Modifiers
C. A method name
D. A list of parameters
E. Return type, or void
F. A body of the method
G. Variables
QUESTION 29