Professional Documents
Culture Documents
Taller Clase Semana 5 - OCA
Taller Clase Semana 5 - OCA
2. Given:
public class Condicional {
public static void main(String args[]){
int x = 0;
int y = 2;
boolean b = ( x != 0 ) && ( ( y / x ) != 0 );
System.out.println(b);
}
}
What is the output?
a. False
b. True
c. Compilation error
d. Runtime exception
3. Given:
public class JavaCertQType4 {
public static void main(String... cmd) {
String a="56";
// INSERT CODE HERE
int b = 589;
int c = 589;
System.out.println (i * b);
}
}
Which options, when inserted individually at //INSERT CODE HERE will enable
class JavaCertQType4 to output value 32984?
a. int i = Integer.parseInt(a);
b. int i = Integer.parseInt(“a”);
c. int i = a;
4. Given:
public class JavaCertQType3 {
}
}
a. Code will compile successfully only if code on line 3 is commented.
b. Code will output the same result if diy is changed to 1diy.
c. Code will compile sucessfully and execute if variable 1a is changed to 12.
d. Code will compile sucessfully and execute if variable 1a is changed to b.
7. Given:
public class JavaCertQType1 {
int a=10;
int b=20;
a += b;
b += a;
System.out.println(a);
System.out.println(b);
}
}
Select incorrect options
a. Code will output 30 y 50
b. Code will output 30 y 30
c. Code will output 30 y 10
d. Code will output 10 y 20
8. Given:
int a=10;
int b=20;
int c=30, d;
d = ++a + b-- + ++c * --a;
System.out.println(d);
}
}
What is the output?
a. Compilation error
b. Runtime exception
c. Code outputs 300
d. Code outputs 309
e. Code outputs 341
9. Given:
int a=10;
int b=20;
int c=30, d;
double f= 50;
d = ++a + b-- + ++c*--a - f;
System.out.println(d);
}
}
10. Give:
public class JavaCertQType1 {
int a=10;
int b=20, c;
a +=b;
b +=a;
c=b++ + ++a;
System.out.print(a==b);
System.out.print(a>=b);
System.out.print(a<=b);
System.out.print(c!=a);
}
}
11. Given:
1- public class JavaCertQType1 {
2- public static void main(String... cmd) {
3- int i = -3;
4- byte b = 5;
5- float f = 1e-10f;
6- double d = 3.14;
7- boolean b1 = i > i;
8- boolean b2 = i < b;
9- boolean b3 = b <= f;
10- boolean b4 = f >= d;
11- boolean b5 = d != 0;
12- boolean b6 = 1 == f;
13- System.out.println(b1);
14- System.out.println( b2);
15- System.out.println( b3);
16- System.out.println(b4);
17- System.out.println(b5);
18- System.out.println(b6);
19- }
20- }
12. Given:
13. Given
public class JavaCertQType1 {
boolean b1 = true;
int b=20;
//insert code
}
}
14. What are the ways to create objects of all the wrapper classes?
a. Constructor, Setter, Getter.
b. Assignment, Static methods.
c. Assignment, Constructor, Static methods.
d. none of the above.
15. Given
public class JavaCertQType1 {
a. True
b. False
16. Given:
public class JavaCertQType1 {
public static void main(String... method) {
String result = "1";
double calificacion = 3;
if (calificacion < 3)
result = "Pierde materia";
else if (calificacion >= 3)
result = "Pasa la materia";
else if (calificacion > 5 )
result = "Error, la nota debe ser de 0.0 - 5.0";
System.out.println(result);
}
}
What is output:
a. Pierde la materia
b. Pasa la materia
c. Error, la nota debe ser de 0.0 - 5.0
d. Compilation error
e. Runtime exception
17. Given:
package ejemplo;
//insert code 1
//insert code 2
else {
System.out.println("no puede beber");
System.out.println(edad);
a.
Code 1: import java.util.Scanner;
Code 2:
System.out.println("puede beber");
}
b.
Code 2:
System.out.println("puede beber");
c.
Code 2:
System.out.println("puede beber")
d.
Code 2:
System.out.println("puede beber");
18. Given:
19. Given:
switch (usuario) {
case "admin":
System.out.println("welcome admin");
break;
case "usuario1":
System.out.println("welcome usuario1");
break;
case "usuario2":
System.out.println("welcome usuario2");
break;
case "invitado":
System.out.println("welcome usuario1");
break;
case "luis":
System.out.println("welcome luis");
break;
case "juan":
System.out.println("welcome juan");
break;
default:
System.out.println("Usuario Invalido?");
break;
}
}
20. Given:
package ejemplo;
import javax.swing.JOptionPane;
public class JavaCertQType1 {
public static void main(String... method) {
String numero = JOptionPane.showInputDialog("numero");
int n = Integer.parseInt(numero));
int resultado;
for(int i=1;i<=n;i++) {
for(int j=1;j<10;j++) {
resultado = i*j;
System.out.println(i + " x " + j + " = " + resultado);
}
}
}
}
24. What's the difference between the While loop and the Do-While loop?
a. The two loops have no difference, the two work in the same way.
b. The while loops checks its condition before evaluating its loop body, and
the do-while loop checks its condition after executing the statements
defined in its loop body.
c. The while loops checks its condition before after executing the
statements defined in its loop body, and the do-while loop checks its
condition before evaluating its loop body.
25. Given:
public class JavaCertQType1 {
public static void main(String... method) {
int numero =1,i=1;
while(numero<30) {
numero=numero+1;
i++;
if(i>=12) {
break;
}
}
System.out.println(numero);
}
}
what is the output?
a. Code output 29.
b. Code output 30.
c. Code output 12.
d. Code won't compile.
26. Which loop to use when you don’t know the number of iterations
beforehand and when the number of iterations depends on a condition being
true?
a. for
b. enhanced for
c. while and do-while
29. Given:
public class JavaCertQType1 {
public static void main(String... method) {
for (int i = 0; i < 3; i++) {
first:
for (int j = 0; j < 3; j++){
if(i == 1){
continue first;
}
System.out.print(" [i = " + i + ", j = " + j + "] ");
}
}
System.out.println();
}
}
30. Given:
1- public class JavaCertQType1 {
2- public static void main(String... method) {
3- String[] programmers = {"luis", "fernando", "juan", "Pedro"};
4- String saludo ="hola ";
5- outer:
6- for (String name1 : programmers) {
7-
8- for (String name : programmers) {
9- if (name.equals("fernando"))
10- break outer;
11- System.out.println(saludo + name);
12- }
13- }
14- }
15- }
Select correct options:
a. Code will compile successfully if code on line 4 is commented.
b. Code will output the same result if code on line 9 is commented.
c. Code will output the same result if code on line 4 is placed after code on
line 5.
d. The code compiles successfully.