Professional Documents
Culture Documents
SURCOLOMBIANA UNIVERSITY
PREPARATION IN JAVA
NEIVA-HUILA
2019
1) char myChar = -122;
System.out.print (myChar);
What is the output ?
a) z
b) -z
c) -122
d) compilation error
e) runtime exception
answer d = in char variables you must change its structure to allow negative
values
answer a, b, c and f = in the a because the variable int does not accept decimal values, in
the b) because the variable is not named properly, in the c) because the name of the
variable should not be named with the% character.
public class ej {
public static void main(String[] args) {
int a = 2;
long b = 3;
short c = 5;
int d = 6;
int e = 8;
System.out.print((((a%b)*c))+(d/e++));
}
}
a) 9
b) 239
c) -10
d) 10
e) Compilation error
4)
public class ej {
public static void main(String[] args) {
boolean x = true;
boolean y = false;
boolean a1 = x && x;
boolean a2 = x && y;
boolean a3 = y && x;
boolean a4 = y && y;
System.out.println( (a1&&a2)==(a3||a4));
}
}
answer b = because false is not different from false then the variable is false
5)
public class ej {
public static void main(String[] args) {
int a = -0;
integer b = 4;
long c4444444 = 355555;
byte d = 0;
}
}
Which of the following options contains the code that it would not execute?
a) System.out.print(a);
b) System.out.print(b);
c) System.out.print(c4444444);
d) System.out.print(d);
6) Which of the following options are the correct way to increase +2 the value of ctr?
) ctr += 2;
a
b) ctr =+ 2;
c) +++ctr;
d) ctr = 2;
answer a = because it tells the variable to increase the initial number by two
7)
public class ej {
public static void main(String[] args) {
int a = 10;
int b = 12;
int c = 29;
int d = (a+c*b);
boolean e;
e = d == 468;
System.out.println(e);
}
}
What should I modify in the d variable so that the code executes correctly?
a) int d = ((a+c)*b);
b) int d = ((a+c)(*b));
c) int d = true;
d) int d = ((a+c)((*b));
answer a = because by putting parentheses the operational hierarchy changes giving the
desired result that is 468
8) What is true about the following lines of code?
public class ej {
public static void main(String[] args) {
char a = 97;
String c = "a";
boolean d;
d = a==c;
System.out.println(d);
}
}
9)
public class ej {
public static void main(String[] args) {
int x = 20;
int y = 40;
which variable must change its value so that the code executes false?
a) the variable x
b) the variable y
c) both variable
10)
a) true
b) false
c) Error in the line 2
d) Error in the line 1