Nothing Special   »   [go: up one dir, main page]

Oracle Java Foundation: Review Modul 6 - 9

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

ORACLE JAVA FOUNDATION

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) ;

B. At line7, insert x --;

C. Replace line 6 with --x; and,


at line 7, insert system, out. print (x);

D. Replace line 12 With return (x > 0) ? false: true;


A. 5 4 3 2 1 0
B. 5 4 3 2 1
C. 4 2 1
D. 5
E. Nothing is printed
A. Replace line 5 With String opt= "true";
Replace line 7 with case "true":

B. Replace line 5 with boolean opt = l;


Replace line 7 with case 1=

C. At line 9, remove the break statement.

D. Remove the default section.


A. 100
B. 101
C. 102
D. 103
E. Compilation fails
A. 97 98 99 100 null null null

B. 97 98 99 100 101 102 103

C. Compilation rails.

D. A NullPointerException is thrown at runtime.

E. An ArraylndexOutOfBoundsException is thrown at

runtime.
A. [Robb, Rick, Bran]

B. [Robb, Rick]

C. [Robb, Bran, Rick, Bran]

D. An exception is thrown at runtime.


A. 3 4 5 6

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];

C. int array = new int[2];

D. int array [2] ;


A. A B C Work done

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. (2) for (int i = 1; i <= end; i++); (3) accumulator *= i;


B. (1) int accumulator = 1; (2) for (int i = 1; i <= end; i++);
C. (1) int accumulator = 1; (3) accumulator *= i;
D. (1) int accumulator = 1; (2) for (int i = start; i <= end; i *= 1);
QUESTION 4

How many times will the loop body be executed?

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

Select all true statements about break and continue.

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

Select all true statements about methods in Java.

A. It's possible to declare a method without parameters.

B. A method must always return a value.

C. A method is always declared inside a class.

D. Method name is not case-sensitive


QUESTION 17

The signature of a method consists of ...

A. the type of a returning value and the parameter types


B. the type of a returning value and the method's name
C. the type of a returning value, the method's name and the
parameter types
D. the method's name and the parameter types
E. The method’s name and the parameter name
QUESTION 18

Which of the following method declarations are syntactically correct and compliant with
the style recommendations?

A. static public void findAirports(String city) { /*...*/ }

B. public void static findAirports(String city) { /*...*/ }

C. void public findAirports(String city) { /*...*/ }

D. public void findAirports(String city) { /*...*/ }

E. public static void findAirports(String city) { /*...*/ }


QUESTION 19

What is a signature of the following method:

A. int abs(int)
B. abs(int)
C. abs
D. int abs
QUESTION 20

Select all correct statements about methods in Java.

A. A method can be declared outside of a class


B. It's possible to declare a method without arguments
C. A method can have the keyword static
D. A method can be named method11
E. A method always has to return a value
QUESTION 21

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. Nothing will happen

B. The program will not be compiled.

C. The program will be compiled and successfully started.

D. The program will be compiled but not started.


QUESTION 22
What will be printed if you compile and run code below?

A. It will compile but throw an error


in runtime
B. I'm the main
C. No! I'm still the main!
D. It will not compile
QUESTION 24

Select a pair of successfully overloaded methods.

A. public static void method1() { /* do something */ }

B. public static void method2() { /* do something */ }

C. public static int method2() { /* do something */ }

D. public static void method3(int a, double b, long c) { /* do something */ }

E. public static void method1(int a, double b) { /* do something */ }

F. public static void method333() { /* do something */ }


QUESTION 28

Which of the following elements are considered as parts of a simple method?

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

What does the following code output?


QUESTION 30
Given code that processes strings:

What is the value of str2?

You might also like