If, Else statements, Switch statements (Control Flow) and comparison operators. Flashcards

1
Q

In a Java Switch statement, when is code in the default clause executed?

A

If either no other clause has been met, or a preceding clause has been met, and there was no break statement in between the preceding clause and the default clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Consider the following code, where productCode is an integer with the value 2.

switch (productCode) {
case 1:
System.out.println(“Left handed screwdriver”);
case 2:
System.out.println(“Tartan Paint”);
case 3:
System.out.println(“Long stand”);
}

What is the output when the code is executed?

A

Tartan Paint

Long stand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is used in conjunction with the equals ‘=’ sign to check if two primitive values are not equal?

A

!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consider the following code, where ‘member’ is a boolean set to ‘true’:

if (member) {
int customerCode = 32;
}

System.out.println(customerCode);

What, if anything, would be printed to the console?

A

Nothing - the program would not run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What data type cannot be switched upon?

A

Double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What expression evaluates if x is greater than y?

A

x > y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Consider the following code where ‘located’ is a boolean set to ‘false’

int credits = 0;

if (!located) {
credits = 15;
}

System.out.println(credits);

What, if anything, would be output to the console?

A

15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of these is used to check for equality of primitive data types in Java?

A

==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly