Expressions Methods if else Statements Loops Potpourri
8 % 20
8
((20 % 8) / 3) * (20 / 8)
2
15 >= 7 >= 0
INVALID
(15 >= 7) && !true
false
(23 / 7 > 2) || (23 % 7 > 2)
true
This line contains a method return type.
45
This line contains a formal parameter
5 or 45
This is the name of one formal parameter.
args, word, letter
This line contains an actual parameter (argument).
15, 20, 22, 27-28, 32, 34, 36, 39, 51
This is one of those actual parameters (arguments)
System.in, any of the output, count, letter, “Y”, pos
T/F, An if statement must contain an else clause.
F
This line contains a boolean expression.
18, 25, 39, 49, 51
This is a boolean expression that will evaluate to true if an integer, num1, is evenly divisible by 5 and false otherwise. This is a boolean expressi o n that will evaluate to This expression evaluates to true if an integer, num1, is evenly divisible by 5 and false otherwise.
num1 % 5 == 0
This is a boolean expression that will evaluate to true if the String, word, is “CS 139” exactly.
word.equals(“CS 139”)
&&, ||, and ! are examples of this.
Logical operators
This line contains a loop decision.
18, 25, 49
This line contains a loop update.
40,42, 29, 49
This is one update statement.
pos++; cont = true (false); letterStr = keyboard.nextLine();
If we had the word, “Jeopardy”, and the letter “z”, how many times would the loop body in countLetter execute.
8 times, once for each letter.
This kind of loop is a post condition loop.
do while
You have a random number generator declared as rand. This statement will generate a number in the range of 13 – 22.
rand.nextInt(10) + 13
This line contains the declaration of a reference type variable.
7, 8, 9, 10, (5), 45
This statement instantiates a reference object.
keyboard = new Scanner(System.in);
This is a primitive literal found in the file.
0, true, false, 1
These are two of the three variables local to the countLetter method.
word, letter, count, pos