You are on page 1of 6

QUESTIONS: DATA TYPES AND OPERATORS

JORGE ANDRÉS CUTIVA TAFUR


CARLOS EDUARDO VELÁSQUEZ GIL

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

2) which of the options are incorrect ?

​a) int a = 2,1;


​b) Boo result = false;
​c) int %Descuento = 25;
d) boolean edad = true;
e) char myChar = 122;
​f) character myChar = 122;
g) int = 2;

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.

3) What is the output of the following code ?

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

answer d = because it follows the operational hierarchy

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

If we change the value of == to != that the code would execute?


a) true
b) false
c) compilation error
d) runtime exception

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

answer b = because the variable is not named properly

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

a) code prints true


b) code prints false
c) code prints 97a
d) Compilation error

answer d = because String and Boolean variables can not be compared

9)

public class ej {
public static void main(String[] args) {

int x = 20;
int y = 40;

boolean e = (x==20 || y==40);


System.out.print(e);
}
}

which variable must change its value so that the code executes false?
a) the variable x
b) the variable y
c) both variable

answer c = why so that || is false the two variables have to be false

10)

int a = 10; // line 1


boolean c = (a=10); // line 2
System.out.print(c); // line 3

What is the result?

a) true
b) false
c) Error in the line 2
d) Error in the line 1

answer c = the expression a = 10 is badly structured equality, it must be done in the


following way (a == 10)

You might also like