What does this code print?
int x = 8;
x = x + 4;
System.out.println(x);
It is 12
What does this loop show?
for (int i = 0; i < 5; i++) {
System.out.print(i);
}
The answer is 0,1,2,3,4
What does it print?
int num = 7;
if (num > 5) {
System.out.println("A");
} else {
System.out.println("B");
}
It is A.
What mistake is in this code?
int num = 10;
if (num = 5) {
System.out.println("Equal");
}
What is using = instead of ==.
This keeps data that can change while the program runs.
It is variable.
What do you see after running the code?
int num = 15;
if (num > 10) {
System.out.println("Greater than 10"); // Prints: Greater than 10
} else {
System.out.println("Not greater than 10");
}
It is Greater than 10
What value comes out?
int sum = 0;
for (int i = 1; i <= 4; i++) {
sum += i;
}
System.out.println(sum);
It is 10
Which letter shows up?
int score = 81;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
It is B.
Why doesn’t this loop work?
for (int i = 0; i <= 5; i--) {
System.out.println(i);
}
There is a loop that keeps running forever.
This repeats code as long as a condition is true.
It is a loop.
What do you see when it runs?
int a = 4;
int b = 2;
a = a * b;
b = a - b;
System.out.println(b);
It is 6.
How many times does the count go up?
int count = 0;
for (int i = 5; i > 0; i--) {
if (i % 2 == 1) {
count++;
}
}
System.out.println(count);
The answer is 3.
What does it print?
int x = 4;
int y = 6;
if (x > 5 && y > 5) {
System.out.println("Both");
} else if (x > 5 || y > 5) {
System.out.println("One");
} else {
System.out.println("None");
}
It is one.
What’s wrong with this loop?
int[] nums = {1, 2, 3};
for (int i = 0; i <= nums.length; i++) {
System.out.println(nums[i]);
}
Past the array’s limits.
This operator sees if two values are the same.
It is ==
What does this code print?
int x = 3;
int y = x + 2;
x = y * 2;
System.out.println(x);
The answer is 10.
What will this print out?
for (int i = 2; i <= 8; i += 2) {
System.out.print(i + " ");
}
It is 2,4,6,8
What will be printed by this code?
int temp = 65;
if (temp > 80) {
System.out.println("Hot");
} else if (temp > 60) {
System.out.println("Warm");
} else {
System.out.println("Cold");
}
The answer is warm.
What’s the problem?
int score = 90;
if (score >= 90);
{
System.out.println("A");
}
The if statement ends with a semicolon.
This keyword immediately ends a loop.
It is a break.
What is printed?
int a = 5;
a++;
a = a * 2;
System.out.println(a);
The answer is 12.
What value does total have at the end?
int total = 1;
for (int i = 1; i <= 3; i++) {
total *= i;
}
System.out.println(total);
The answer is 6.
What does the program display?
int x = 10;
if (x < 5 || x > 8) {
System.out.println("True");
} else {
System.out.println("False");
}
It is true
Where is the mistake?
int x;
System.out.println(x);
The variable was not given an initial value.
This tests whether both conditions are true at the same time.
It is &&