Quiz
Chapter 2 Operators and Statements
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (20)
1Which of the following Java operators can be used with boolean variables? (Choose all that
apply)- AA. ==
- BB. +
- CC. --
- DD. !
- EE. %
- FF. <=
2What data type (or types) will allow the following code snippet to compile? (Choose all that
apply)
byte x = 5;
byte y = 10;
_____ z = x + y;- AA. int
- BB. long
- CC. boolean
- DD. double
- EE. short
- FF. byte
3What is the output of the following application?
1: public class CompareValues {
2: public static void main(String[] args) {
3: int x = 0;
4: while(x++ < 10) {}
5: String message = x > 10 ? "Greater than" : false;
6: System.out.println(message+","+x);
7: }
8: }- AA. Greater than,10
- BB. false,10
- CC. Greater than,11
- DD. false,11
- EE. The code will not compile because of line 4.
- FF. The code will not compile because of line 5.
4What change would allow the following code snippet to compile? (Choose all that apply)
3: long x = 10;
4: int y = 2 * x;- AA. No change; it compiles as is.
- BB. Cast x on line 4 to int.
- CC. Change the data type of x on line 3 to short.
- DD. Cast 2 * x on line 4 to int.
- EE. Change the data type of y on line 4 to short.
- FF. Change the data type of y on line 4 to long.
5What is the output of the following code snippet?
3: java.util.List<Integer> list = new java.util.ArrayList<Integer>();
4: list.add(10);
5: list.add(14);
6: for(int x : list) {
7: System.out.print(x + ", ");
8: break;
9: }- AA. 10, 14,
- BB. 10, 14
- CC. 10,
- DD. The code will not compile because of line 7.
- EE. The code will not compile because of line 8.
- FF. The code contains an infinite loop and does not terminate.
6What is the output of the following code snippet?
3: int x = 4;
4: long y = x * 4 - x++;
5: if(y<10) System.out.println("Too Low");
6: else System.out.println("Just right");
7: else System.out.println("Too High");- AA. Too Low
- BB. Just Right
- CC. Too High
- DD. Compiles but throws a NullPointerException.
- EE. The code will not compile because of line 6.
- FF. The code will not compile because of line 7.
7What is the output of the following code?
1: public class TernaryTester {
2: public static void main(String[] args) {
3: int x = 5;
4: System.out.println(x > 2 ? x < 4 ? 10 : 8 : 7);
5: }}- AA. 5
- BB. 4
- CC. 10
- DD. 8
- EE. 7
- FF. The code will not compile because of line 4.
8What is the output of the following code snippet?
3: boolean x = true, z = true;
4: int y = 20;
5: x = (y != 10) ^ (z=false);
6: System.out.println(x+", "+y+", "+z);- AA. true, 10, true
- BB. true, 20, false
- CC. false, 20, true
- DD. false, 20, false
- EE. false, 20, true
- FF. The code will not compile because of line 5.
9How many times will the following code print "Hello World"?
3: for(int i=0; i<10 ; ) {
4: i = i++;
5: System.out.println("Hello World");
6: }- AA. 9
- BB. 10
- CC. 11
- DD. The code will not compile because of line 3.
- EE. The code will not compile because of line 5.
- FF. The code contains an infinite loop and does not terminate.
10What is the output of the following code?
3: byte a = 40, b = 50;
4: byte sum = (byte) a + b;
5: System.out.println(sum);- AA. 40
- BB. 50
- CC. 90
- DD. The code will not compile because of line 4.
- EE. An undefined value.
11What is the output of the following code?
1: public class ArithmeticSample {
2: public static void main(String[] args) {
3: int x = 5 * 4 % 3;
4: System.out.println(x);
5: }}- AA. 2
- BB. 3
- CC. 5
- DD. 6
- EE. The code will not compile because of line 3.
12What is the output of the following code snippet?
3: int x = 0;
4: String s = null;
5: if(x == s) System.out.println("Success");
6: else System.out.println("Failure");- AA. Success
- BB. Failure
- CC. The code will not compile because of line 4.
- DD. The code will not compile because of line 5.
13What is the output of the following code snippet?
3: int x1 = 50, x2 = 75;
4: boolean b = x1 >= x2;
5: if(b = true) System.out.println("Success");
6: else System.out.println("Failure");- AA. Success
- BB. Failure
- CC. The code will not compile because of line 4.
- DD. The code will not compile because of line 5.
14What is the output of the following code snippet?
3: int c = 7;
4: int result = 4;
5: result += ++c;
6: System.out.println(result);- AA. 8
- BB. 11
- CC. 12
- DD. 15
- EE. 16
- FF. The code will not compile because of line 5.
15What is the output of the following code snippet?
3: int x = 1, y = 15;
4: while x < 10
5: y––;
6: x++;
7: System.out.println(x+", "+y);- AA. 10, 5
- BB. 10, 6
- CC. 11, 5
- DD. The code will not compile because of line 3.
- EE. The code will not compile because of line 4.
- FF. The code contains an infinite loop and does not terminate.
16What is the output of the following code snippet?
3: do {
4: int y = 1;
5: System.out.print(y++ + " ");
6: } while(y <= 10);- AA. 1 2 3 4 5 6 7 8 9
- BB. 1 2 3 4 5 6 7 8 9 10
- CC. 1 2 3 4 5 6 7 8 9 10 11
- DD. The code will not compile because of line 6.
- EE. The code contains an infinite loop and does not terminate.
17What is the output of the following code snippet?
3: boolean keepGoing = true;
4: int result = 15, i = 10;
5: do {
6: i--;
7: if(i==8) keepGoing = false;
8: result -= 2;
9: } while(keepGoing);
10: System.out.println(result);- AA. 7
- BB. 9
- CC. 10
- DD. 11
- EE. 15
- FF. The code will not compile because of line 8.
18What is the output of the following code snippet?
3: int count = 0;
4: ROW_LOOP: for(int row = 1; row <=3; row++)
5: for(int col = 1; col <=2 ; col++) {
6: if(row * col % 2 == 0) continue ROW_LOOP;
7: count++;
8: }
9: System.out.println(count);- AA. 1
- BB. 2
- CC. 3
- DD. 4
- EE. 6
- FF. The code will not compile because of line 6.
19What is the result of the following code snippet?
3: int m = 9, n = 1, x = 0;
4: while(m > n) {
5: m--;
6: n += 2;
7: x += m + n;
8: }
9: System.out.println(x);- AA. 11
- BB. 13
- CC. 23
- DD. 36
- EE. 50
- FF. The code will not compile because of line 7.
20What is the result of the following code snippet?
3: final char a = 'A', d = 'D';
4: char grade = 'B';
5: switch(grade) {
6: case a:
7: case 'B': System.out.print("great");
8: case 'C': System.out.print("good"); break;
9: case d:
10: case 'F': System.out.print("not good");
11: }- AA. great
- BB. greatgood
- CC. The code will not compile because of line 3.
- DD. The code will not compile because of line 6.
- EE. The code will not compile because of lines 6 and 9.
Informações
- Descrição
- OCA java 8 JAVA 8 Quiz sobre Chapter 2 Operators and Statements, criado por davidv em 23-04-2016.
- Autor
- davidv
- Idioma
- Español
- Visualizações
- 0
- Etiquetas
- Avaliação
- Ainda sem avaliações Avalie este quiz