1/34
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Designate a boolean variable with a value for if one is greater than two.
boolean b = 1 > 2;
Relational operators.
Operators that compare two values, resulting in a boolean value (true or false).
Relational operator for less than.
<
Relational operator for less than or equal to
<=
Relational operator for greater than.
>
Relational operator for greater than or equal to.
>=
Relational operator for equal to
==
Relational operator for not equal to.
!=
Do if statements need parentheses?
Yes
Do if statements need braces?
No
If statement syntax.
if (x > y) {
//statements
}
If-else statement syntax.
if (x > y) {
//true statements
}
else {
//false statements
}
if-else if-else syntax
In an if statement block, the “else” clause always matches with…
…the most recent “if“ clause in the block.
Nested if statement.
An if statement contained within another if statement.
Simplify:
if (even == true)
if (even)
Write a program that computes and interprets BMI.
Test cases
70kg, 2m
80kg, 2m
100kg, 2m
200kg, 2m
70kg, 2m: Underweight
80kg, 2m: Normal
100kg, 2m: Overweight
200kg, 2m: Obese
Logical operator for “not“
!
Logical operator for “and“
&&
Logical operator for inclusive “or“
||
(returns true if one or both conditions are true)
Logical operator for exclusive “or“
^
(returns true if one condition is true, but not both)
Test cases
2000:
2003:
2004:
Test cases
2000: leap year
2003: not leap year
2004: leap year
Switch statement syntax.
In a switch statement, the switch expression in parentheses must be of … data type.
char, byte, short, or int
In a switch statement, the case values must be of what data type?
The same data type as the switch expression.
The case value in a switch statement is a …1… , and therefore cannot be a …2…
1. Constant
2. Variable
What happens when a switch statement has no break statements?
All cases will be executed, starting with the case that matches the switch expression.
express using the conditional operator:
Logic errors are also called…
bugs