What is the output of the following code?
int x = 10;
if (x++ > 10) {
System.out.println("greater");
} else {
System.out.println("not greater");
}
System.out.println(x);
Loading test…
12 questions
What is the output of the following code?
int x = 10;
if (x++ > 10) {
System.out.println("greater");
} else {
System.out.println("not greater");
}
System.out.println(x);
Which expression is equivalent to !(a && b) according to De Morgan's Law?
What does the following code print?
int a = 5;
int b = 5;
System.out.println(a == b);
String s1 = new String("hello");
String s2 = new String("hello");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
Which boolean expression correctly checks whether x is between 1 and 10 (inclusive)?
What is the output of the following code?
int a = 3;
int b = 7;
if (a > 0 && ++b > 7) {
System.out.println("yes");
} else {
System.out.println("no");
}
System.out.println(b);
What is the output of the following code?
int score = 85;
String grade;
if (score >= 90) {
grade = "A";
} else if (score >= 80) {
grade = "B";
} else if (score >= 70) {
grade = "C";
} else {
grade = "F";
}
System.out.println(grade);
What is the output of the following code?
int x = 4;
if (x % 2 == 0)
System.out.println("even");
System.out.println("positive");
Which of the following best demonstrates short-circuit evaluation of &&?
String s = null;
if (s != null && s.length() > 0) {
System.out.println("Non-empty");
} else {
System.out.println("Null or empty");
}
What is the output of the following code?
boolean x = true;
boolean y = false;
if (x || y) {
System.out.print("1 ");
}
if (x && y) {
System.out.print("2 ");
}
if (!y) {
System.out.print("3 ");
}
What is the output of the following code?
boolean a = true;
boolean b = false;
System.out.println(!a || b);
System.out.println(!(a || b));
What is the output of the following code?
int x = 0;
if (x = 5) {
System.out.println("hello");
}
What is the output of the following code?
int x = 5;
if (x > 3) {
System.out.println("A");
} else if (x > 4) {
System.out.println("B");
} else {
System.out.println("C");
}