If, Else statements, Switch statements (Control Flow) and comparison operators. Flashcards
In a Java Switch statement, when is code in the default clause executed?
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.
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?
Tartan Paint
Long stand
What is used in conjunction with the equals ‘=’ sign to check if two primitive values are not equal?
!
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?
Nothing - the program would not run.
What data type cannot be switched upon?
Double
What expression evaluates if x is greater than y?
x > y
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?
15
Which of these is used to check for equality of primitive data types in Java?
==