Data Type
Variables
Input / Output
if statements
Loops (for / while)
100

What data type would you use to store the number 9.6?

double

100

Declare a variable to store the number 5

int number = 5;

100

What will the following code print?

System.out.print("3");

System.out.print("5");


35

100

int x = 10; 

if (x == 5) {    System.out.println("x is 5"); } 

else {    System.out.println("x is not 5"); }

x is not 5

100

How many times will this loop run?

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

3 times

200

What happens if you try to store a decimal number in an int variable?

You get a compilation error
200

If you declare int x = 10; and then assign x = 20;, what is the new value of x?

20

200

What is the Java command to get input from the user?

Scanner input = new Scanner(System.in);

200

What is the purpose of the else if statement?

To check another condition if the if condition is false.

200

Write a while loop that prints numbers from 1 to 5.

int i = 1;
while (i <= 5) {
    System.out.println(i);
    i++;
}

300

Write a Java code that creates a String variable called letter and assigns it the value "Turtle". Then, print out the value of letter.

String letter = "Turtle";        System.out.println(letter);  

300

Write a Java code that declares a variable a of type int and assigns it the value 3, then prints it out.

int a = 3;

System.out.println(a);

300

What is the output of this expression

int a = 6 + 3 * 2 - 4 / 2 + 5 % 2;

System.out.println(a);

11

300

Write an if-else statement to check if a number is positive, negative, or zero.

if (number > 0) {System.out.println("Positive"); }

else if (number < 0) {System.out.println("Negative");}

else {    System.out.println("Zero"); }

300

What does this loop print?

for (int i = 5; i > 0; i--) 

{    System.out.print(i + " "); }

5 4 3 2 1

400

double num = 3;

System.out.println(num);

What is the output?

3.0

400

Write a Java code that declares two int variables, x and y, assigns x the value 5 and y the value 10, then prints their sum.

int x = 5;

int y = 10;

System.out.println(x + y);

400

What is the output of the following?

public class Main {

    public static void main(String[] args) {

        int x = 30;

        int y = 6;

        System.out.println(5 + 11 * y / 3 - x);

    }

}

-3

400

What is returned by the following method when the input is 10?

public boolean isDivisibleByThree(int number) {   

    if (number % 3 == 0) {

        return true;

    } else {

        return false;

    }

}

false

400

What is the output of the following code?

public class Main {

    public static void main(String args[]) {

        for (int i = 1; i <= 20; i+=3) {

            if (i % 2 == 0) {

                System.out.println(i);   

            }

        }

    }

}

4

10

16

500

Write a Java code that uses a boolean variable called isRaining to check if it’s raining and then prints "It is raining" if isRaining is true or "It is not raining" if isRaining is false.


boolean isRaining = true; 

if (isRaining) { System.out.println("It is raining");} else { System.out.println("It is not raining");   }

500

Write a Java code that declares a variable count of type int, assigns it the value 7, then multiplies it by 2 and prints the result.

int count = 7;

count = count * 2;

System.out.println(count);

500

What is returned by the method when the input is "HugeString"?

public boolean mysteryMethod(String mysteryInput) {

    if (mysteryInput.length() > 9) {

        return true;

    } else {

        return false;

    }

}

true;

500

int x = 5; 

if (x > 3) 

System.out.println("Hello");    System.out.println("World");

World

500
Write a for loop to print every odd number between 1 and 50 (Make sure every number is printed on a new line!) I.e
1
3
5

for (int i = 1; i <= 50; i+=2) {

            System.out.println(i);

}