Trace The Code
Loop Logic
If / Else Reasoning
Debug The Idea
Vocabulary & Concepts
100

int x = 8;
x += 6;
System.out.println(x);

What does this print?

Answer: 14



Explanation: The code adds 6 to the initial value which is 8, so the output would be 14.

100

for (int i = 0; i < 5; i++) {
     System.out.println(i + “ “);
}

What does this print?

Answer: 0 1 2 3 4



Explanation: The loop starts at 0 and runs until it stops before 5, printing the value of i during each iteration.

100

int score = 85;
if (score >= 60) {
   System.out.println(“Pass”);
} else {
   System.out.println(“Fail”);
}

What does this print?

Answer: Pass


Explanation: Because the condition says if the score is greater than 60 it should print “Pass” but if it’s less it should print “Fail”, 85 is greater than 60 so “Pass” is printed.

100

int x = 9;
if (x = 7) {
   System.out.println(“Equal”);
}

What is wrong?

Answer: The if statement uses = instead of ==.


Explanation: In Java, = assigns a value, but for comparison, == should be used.

100

What does the keyword ‘else’ do in an if/else statement?

Answer: it provides another block of code that executes if the if condition is false.

Explanation: else allows the program to specify what to do when the if condition is not met.

200

int a = 10;
if (a > 4) {
   a += 2;
}
System.out.println(a);

What does this print?

Answer: 12


Explanation:  The initial value, a is 10, which is greater than 4 meaning the condition is true. so a should be added to 2 which would equal to 12.

200

int count = 0;
for (int i = 12; i > 0; i -= 2) {
     count++

}
System.out.println(count);

What does this print?

Answer: 6


Explanation:  i takes values of 12, 10, 8, 6, 4, 2, stopping after 5 iterations, making the count equal to 6.

200

int age = 25;
if (age >= 18) {
   System.out.println(“Adult”);
} else {
    System.out.println(“Minor”);

}

What does this print?

Answer: Adult


Explanation: Because the condition says if age is greater than or equal to 18, it should print “Adult”, but if not it should print out “Minor”. 25 is greater than 18 which should print out “Adult”.

200

for (int i = 0; i <= 10; i--) {
      System.out.println(i);
}

What is wrong?

Answer: The loop decreases i instead of increasing, causing an infinite loop.


Explanation: The condition i <= 10 and i-- will cause i to decrease infinitely, never ending the loop.

200

What is a loop that runs a specific number of times called?

Answer: A for loop


Explanation: A for loop repeats code a set number of times, it’s controlled by a counter variable.

300

int sum = 0;
for (int i = 1; i <= 7; i++){
      sum += i;
}
System.out.println(sum);

What does this print?

Answer: 28


Explanation: The loop adds numbers 1 through 7 to sum, giving us a result of 1+2+3+4+5+6+7 = 28.

300

int total = 0;
for (int i = 1; i <= 8; i++) {
     if (i % 2 == 0) {
        total += i;
    }
}

What does this print?

Answer: 20


Explanation: The loop adds only even numbers between 1 and 8. It would be 2+4+6+8 which equals to 20.

300

int num = 16;
if (num % 4 == 0 && num > 10) {
   System.out.println(“Special”);
} else {
   System.out.println(“Normal”);
}

What does this print?

Answer: Special


Explanation: The value 16 meets both conditions, it’s divisible by 4 and greater than 10, making the program print “Special”.

300

int total = 0;
for (int i = 0; i < 5; i++) {
     if (i = 3) {
        total += i;
     }
}
System.out.println(total);

What is wrong?

Answer: The condition if (i = 3) uses assignment instead of comparison.


Explanation: It should be (i == 3) because its a comparison operator, it checks that the current value stored in the variable is equal to 3, while (i = 3) sets the value of variable i to 3.

300

Explain the concept of “short-circuit evaluation” in logical operators.

Answer: In a logical AND (&&) or OR (||) expression, evaluation stops as soon as the result is resolved.


Explanation: In a && b, if a is false then b is not evaluated, since the expression cannot be true. similarly with a || b, if a is true, b is not evaluated.

M
e
n
u