Variables | Math and Boolean Expressions | Conditionals | Loops | Arrays |
---|---|---|---|---|
int, double, boolean, char, float
Name three different types of primitive variables.
|
TRUE
Evaluate NOT TRUE OR TRUE
|
if, if/else, else if
Name the three types of conditional statements.
|
for, while
What are the two main types of loops?
|
vehicles[1]
How would you access “car” in the following array? vehicles = [“bus”, “car”, “train”, “truck”]
|
A primitive variable is a basic data type defined by the coding language and its reserved works but a non-primitive type variable is often created by the programmer and isn't defined in the coding language.
What is the difference between a primitive variable and non-primitive variable?
|
True
What does this expression evaluate to?
(True and True) or (False or False) and (False or False) |
“Perfect number of books!”
“Time to read...”
What will be printed?
int numBooks = 25 if (numBooks < 10) { System.out.println(“I need more books!”); } else if (numBooks > 30) { System.out.println(“Where do I put all my books??”); } else { System.out.println(“Perfect number of books!”); } System.out.println(“Time to read...”); |
50 times
How many times “Girls Who Code” be printed out?
int i = 0; while (i < 10) { for (int j = 0; j < 5; j++) { System.out.println(“Girls Who Code”); } i++; } |
boba
Drinks = [[‘coffee’, ‘tea’, ‘boba’], [‘smoothie’, ‘juice’, ‘soda]]
What is returned by drinks[0][2]? |
new, full name
Which of the following are invalid variable names:
new, name, full name, age? |
false
If i = 5, evaluate i >= 2 AND i < 4
|
Nothing is printed!
What is printed by the following code?
int numDogs = 5; if (numDogs < 5) { System.out.println(“Woof!”); } else if (numDogs > 5) { System.out.println(“Woof Woof!!”); } |
120
What will be returned?
y = 5 count = 0 while (y >= 0): for x in range(20): count += 1 y -= 1 return count |
True, for example, arr[-1] would return the last element of arr, arr[-2] would return the second to last element of arr, and so on.
True or False… python supports negative indexing for arrays.
|
No, because when we try to store a double in an int, it is a lossy conversion.
Is this valid, why or why not?
int height = 180.65; |
true
Evaluate the boolean expression NOT((3==2) AND ((3 != 1.5 * 2) OR true))
|
if (testScore < 60) {
System.out.println(“F”); } else if (testScore < 70 && test score >= 60) { System.out.println(“D”); } else if (testScore < 80 && test score >= 70) { System.out.println(“C”); } else if (testScore < 90 && test score >= 80) { System.out.println(“B”); } else { System.out.println(“A”); }
Given a testScore variable between 0 and 100, write code that will print out the letter grade.
|
8
11 14 17
What will be printed?
x = 5; while (x < 17): x += 3 print(x) |
int[] arr = new int[10]
for (int i = 0; i < arr.length; i++) { arr[i] = 2*i + 5; }
Write code in Java that accomplishes the following task (use a for loop): for each index i of an array of length 10, store 2*i + 5 in that index.
|
5 different variables of the types: int, double, boolean, char, String
Initialize and declare 5 variables, each of a different data type (primitive and non-primitive).
|
Answers may vary
Example: NOT((5 != 5) OR ((7 < 3) AND (13 == 13)))
Write a boolean expression, which evaluates to true, and contains <, and, or, not, !=, ==
|
if (temperature > 70):
print ("Warm") else: print("Cold")
Write a conditional statement to evaluate and let you know whether it is cold or warm (by using the temperature variable, which is already defined). If the temperature is above 70, then it is warm, otherwise it is cold.
|
10
What does the following code print?
int[] nums = {5, 1, 4, 3, 7}; int sum = 0; for (int i = 2; i >= 0; i--) { sum += nums[i] } System.out.println(sum); |
Out of bounds error
fruits = [[strawberries, blueberries, raspberries], [peach, plum], [orange]]
What is returned by fruits[2][1]? |