H
E
L
L
O
200

What does this loop print?

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


1  

2  

3

200

Q: What does int x = 5 + 3 * 2; set x to?

11


200

System.out.println("Hello, world")

missing a semicolon

System.out.println("Hello, world");

200

Q:
What does this print?


boolean isSunny = true;
if (isSunny) {
    System.out.println("Go outside!");
} else {
    System.out.println("Stay inside.");
}


Go outside!


200

What does this print?


String word = "hello";
System.out.println(word.length());


5

400

What's wrong with this loop?

int x = 0;
while (x < 5)
    System.out.println(x);
    x++;


Only the first line is inside the loop. Fix it with curly braces:

while (x < 5) {
    System.out.println(x);
    x++;
}


400

Q: What does System.out.println(10 % 4); print?


2

400

Q:
What is printed by this?

int a = 5;
double b = a;
System.out.println(b);


5.0


400

int x = 5;

if (x > 0 && x < 10) {

    System.out.println("x is between 1 and 9");

}

else{

    System.out.println("Bye");

}

x is between 1 and 9

400

Q:
What is the output?

String a = "Java";
String b = "Java";
System.out.println(a == b);


true


600

Fix the bug in this for loop so it prints only even numbers from 2 to 10.

for (int i = 2; i <= 10; i++)
    if (i % 2 = 0)
        System.out.println(i);


Use == instead of = for comparison:


if (i % 2 == 0)


600

What will this print?

int x = 8;
if (x % 2 == 0) {
    System.out.println("Even");
} else {
    System.out.println("Odd");
}


Even


600

String s = "Hello";

s = s + " World";

System.out.println(s.length());

11

600

How do you set up a while loop?

while (condition is true) {

      do this;

}

600

What’s wrong here?

String name = "Alice";
if (name = "Alice") {
    System.out.println("Welcome!");
}


Use .equals() instead of =

800

What will this code print?

int i = 5;
while (i >= 0) {
    System.out.print(i + " ");
    i--;

}


5 4 3 2 1 0


800


int num1=7;

int num2=2;

What does System.out.println(num1 / num2); print in Java?


3 (integer division — decimal is dropped)

800

if x == 10 {

    System.out.println("Ten!");

}

missing parenthesis around x==10

800

Q:
Whats wrong with this
String 2ndPlayer;


No — variable names cannot start with a digit

800

What does this print?

String text = "Computer";
System.out.println(text.substring(0, 4));


Comp


1000

int x = 3;

while (x < 10) {

    System.out.println("x: " + x);

    x += 2;

}

x: 3  

x: 5  

x: 7  

x: 9

1000

: What does this print?

int x = 3;
int y = 4;
if (x * y > 10) {
    System.out.println(x + y);
} else {
    System.out.println(x - y);
}


7

(Because 3 * 4 = 12, which is greater than 10 → prints x + y → 3 + 4)

1000

scannner scanner = new Scanner(System.in)

System.out.print("Enter your age: ")

int age = input.nextLine()

if (age >= 18) {

    System.out.println("You're an adult!")

}

1.  second scanner should be capital

2.semicolon

3.nextInt

4.semicolon

1000

int x = 0;

while (x < 4) {

    System.out.println(x);

    x--;

}

infinitely

1000

 1000-Point Question – What Does This Print?

javaCopyEdit

String text = "JavaProgramming";
System.out.println(text.substring(4, text.length()));


Programming