This primitive type stores whole numbers (no decimals).
What is int?
This String method returns the number of characters.
What is length()?
The Java operator that means “not equal to.”
What is !=?
The loop most commonly used when you know exactly how many times to repeat.
What is a for loop?
A variable defined in a class that belongs to each object (each instance).
What is an attribute / instance variable / field?
In Java, what is the value of 7 / 2 if both are int?
What is 3?
What does this return?
String s = "computer";
s.substring(1, 4);
What is "omp"?
What does this evaluate to?
What is true?
What is printed?
int sum = 0;
for (int i = 1; i <= 3; i++) sum += i;
System.out.println(sum);
What is 6?
The keyword that refers to the current object.
What is this?
Write an expression to get the last digit of a positive integer n.
What is n % 10?
Which method checks if two Strings have the same characters (case-sensitive)?
What is equals()?
Rewrite using De Morgan’s Law: !(x > 10 || y < 0)
What is (x <= 10 && y >= 0)?
In a countdown loop like for (int i = 10; i >= 1; i ___ ), what goes in the blank?
What is -- (or i--)?
Write a correct constructor header for Book with String title and int pages.
What is public Book(String title, int pages)?
What is the value of y?
double x = 5;
int y = (int)(x / 2);
What is 2?
What does this return?
"banana".indexOf("na")
What is 2?
What is n after this code runs?
int n = 7;
if (n % 2 == 0) n += 10;
else n += 1;
What is 8?
What is the final value of count?
int count = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {
count++;
}
}
What is 6?
If you have private int balance;, write a correct accessor method header.
What is public int getBalance()?
What is the value of c?
int a = 3, b = 4;
double c = (double) a / b;
What is 0.75?
Give one correct expression to get the last character of s as a String, using substring.
What is s.substring(s.length() - 1)?
Why is this condition safe from dividing by zero?
(a != 0 && b / a > 2)
What is “because of short-circuit evaluation”?
(the second part isn’t evaluated if a != 0 is false)
What is the bug in this code?
int i = 0;
while (i < 5) {
System.out.print(i + " ");
}
What is “it’s an infinite loop because i never changes (missing i++)”?
If Counter starts at 0, what is c1’s count after this?
Counter c1 = new Counter();
Counter c2 = c1;
c2.add();
What is 1 (because both references point to the same object)?