True or false?
4 >= 10
False
What is the syntax for a print statement?
What do we put in parentheses when writing an if-statement?
e.g. if (what is this thing) {}
Condition
What are the three parts of a for-loop?
Initialization, Condition, Update
The space where a variable exists
What is scope?
List all the relational operators you remember (at least 4):
>=, <=, >, <, !=, ==, &&, ||
What is the syntax for an if-else statement?
if (condition) {
} else {
}
How many statements can be executed in a single conditional?
e.g.
if (condition) {
// Statement
} else if (condition) {
// Statement
} else {
// Statement
}
1 statement
What is the difference between:
i++
and
i = i + 1 ?
There is no difference :)
Will x have a scope outside the loop?
for (int x = 0; x < 20; x *= 3) {
}
How are logical operators different from other relational operators (like >=) ?
They can only be used with boolean values.
What is the syntax of a for-loop?
for (initialization; condition; update) {
}
Why would you use an else-if?
When you have more than one condition you want to check
How many times will the loop run?
for (int i = 1; i < 10; i++) {
// more code
}
9 times
Can variable 'pies' be used in the inner loop?
for (int pies = 20; pies > 0; pies--) {
for (int chicken = 2; chicken < 5; chicken ++) {
}
}
Yes
Difference between = and ==
What is the difference between assignment and checking equality?
What 3 problems are wrong with the syntax of this print statement:
system.out.print("hello! \")
1. System has a capital S
2. Need another ", the escape sequence means that it is not the end of the String.
3. Need a semi-colon
What values of x would make the else clause run?
if (x % 2 == 0) {
} else {
}
Any odd number
How many times would the loop run?
for (int x = 12; x > 0; x++) {
// more code
}
Infinite times
Where is the variable in-scope?
// Line A
for (int i = 0; i < 4; i++) {
if (i > 2) {
// Line B
} else {
System.out.println("Hooray!");
} // Line C
} // Line D
Evaluate (4 % 2 == 1) && ((37 * 53 + 6 % 3) == 2)
false
**remember short-circuited evaluation!
fun fact: 37*50 + 6 % 3 == 1850
What is the syntax for an if-else-if-else conditional?
if (condition) {
} else if (condition) {
} else {
}
Which values of x would make the else-if run?
if (x > 100) {
} else if (x < 200) {
} else {
}
Any value less than or equal to 100
How many times would this loop run?
for (int rows = 0; rows < 10; rows++) {
System.out.println("I am a Jedi!");
rows++;
}
5 times
Where is the variable 'a' in scope?
// Line A
if (dogs > 0) { // Line B
for (double a = 0; a < 20.0; a += 3) {
dogs++; // Line C
} // Line D
} else {
// Line E
} // Line F
C