The return type for Math.abs()
What is double?
abMethod("mississippi", "ss") when
public static String abMethod(String a, String b) {
int x = a.indexOf(b);
while (x >= 0) {
a = a.substring(0, x) + a.substring(x + b.length());
x = a.indexOf(b);
}
return a;
}
What is "miiippi"?
parent class Triangle has a constructor with signature public Triangle( int a, int b, int c )
subclass Equilateral has a constructor with signature public Equilateral( int a ) {
// fill this in
}
What is
super( a, a, a );
An equivalent statement to !(A && !B) using DeMorgans Law
What is !A || B?
The correct way to find how many elements are in the ArrayList called books
What is books.size()?
The value of x when
int x = 21/5;
What is 4?
rearrange("orange") when...
public static String rearrange(String str) {
String temp = "";
for (int i = str.length() - 1; i > 0; i--) {
temp += str.substring(i - 1, i);
}
return temp;
}
Find the error
parent class Animal has methods move and eat
subclass Bird has methods fly and eat
Animal b1 = new Bird();
Bird b2 = new Bird();
b2.move();
b1.fly();
What is b1.fly()?
Values for a and b which will evaluate c to true when
boolean c = (a || b) && (!a || b);
What is b = true?
The value of y when
double y = (double)(33/5);
What is 6.0?
ArrayList<Integer> numList = new ArrayList<Integer>();
numList.add(3);
numList.add(2);
numList.add(1);
numList.add(1, 0);
numList.set(0, 2);
System.out.print(numList);
What is [2, 0, 2, 1]?
Give an example of a static method and what makes static useful
Math.random() is a static method
We don't have to create a Math object to use it
The code for printing out "Yay" when a number x is even and positive, "Boo!" when x is odd and negative, "Wha?" if x is odd and positive
What is (something like)
if ( x > 0 ) {
if (x % 2==0)
System.out.print("Yay");
else
System.out.print("Wha?");
else {
if (x % 2 == 1)
System.out.print("Boo!");
}
int[][] arr = {{1, 5}, {2, 6}, {3, 7}, {4, 8}};
The code that prints out 1 2 3 4 5 6 7 8
What is
for ( int c = 0; c < arr[0].length; c++ )
for ( int r = 0; r < arr.length; r++ )
System.out.print( arr[r][c] + " " );
The possible values of a when
int a = (int)(Math.random()) * 4 + 6;
What is 6?
x is .... when
int[][] values = {{1, 2, 3}, {4, 5, 6}};
int x = 0;
for (int j = 0; j < values.length; j++) {
for (int k = 0; k < values[0].length; k++) {
if (k == 0) {
values[j][k] *= 2;
}
x += values[j][k];
}
}
What is x = 26?
The error & the correction in...
public class Student {
private String name;
private int id;
public Student(String n, int i) {
n = name;
id = i;
}
}
What is n = name? It should be name = n;
The logic error in the code below:
// Children 3 and under are free
// Ages 4 to under 18: $10 per ticket
// Senior citizen 65 +: $10 per ticket
// All others: $20 per ticket
int price = 0;
if ( age < 18 )
price = 10
else
if ( age >= 65 )
price = 10
else
price = 20
What is...
ages 3 and under will not be free
if ( age >= 4 && age < 18 )
price = 10
The last letter in the 3rd String in the ArrayList called words
What is
words.get(2).substring(words.get(2).length()-1)?
The code for a random even number between 10 and 20 (inclusive)
What is...
((int)(Math.random() * 6) + 5) * 2
stars(4); when...
public static void stars(int num){
if (num == 1) {
return;
}
stars(num - 1);
for (int i = 0; i < num; i++) {
System.out.print("*");
}
System.out.println();
}
What is...
**
***
****
The header for BasketballShoe based on this hierarchy
Footwear
|
Shoe
|
BasketballShoe
What is
public class BasketballShoe extends Shoe?
The name boolean came from...
Who is George Boole?
The remainder when dividing the last int in an int array called nums by 2
nums[nums.length-1] % 2