Given two int values, return their sum. Unless the two values are the same, then return double their sum.
Fill in the blank
public int sumDouble(int a, int b) {
return (_________);
}
a != b? a + b : 4 * b
This keyword is used to refer to a parent object
super
What is a class
All Java codes are defined in a Class. It has variables and methods.
what is 1001 as a decimal
9
what does this do?
public boolean sleepIn(boolean weekday, boolean vacation) {
if (!weekday)
return true;
else if (vacation)
return true;
else
return false;
}
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.
Fill in the blank
public boolean lastDigit(int a, int b) {
return (_______________);
}
a % 10 == b % 10
specifies a block of Java code to be executed if a condition is false in an if statement
Else
make an array that is 10 ints long
int [] = new int[10]'
what is 27 in binary
11011
what does this do?
public String delDel(String str) {
String[] temp = str.split("del");
return (str.length() > 4 ? temp[0].length() == 1 ? temp[0] + temp[1] : str : str.equals("adel") ? "a" : str);
}
Given a string, if the string "del" appears starting at index 1, return a string where that "del" has been deleted. Otherwise, return the string unchanged.
Start with 2 int arrays, a and b, of any length. Return how many of the arrays have 1 as their first element.
Fill in the blank
public int start1(int[] a, int[] b) {
int intss = 0;
intss += (a.length > 0? a[0] ==1?1:0:0);
intss += (b.length > 0? _____________);
return (intss);
}
b[0] ==1?1:0:0
To access the interface methods, the interface must be _______
implements
What is an Object?
An instance of a class is called an object. The object has state and behavior.
what is 2048 in binary
100000000000
what is 2341567981 in binary
10001011100100010111110111101101
Given n of 1 or more, return the factorial
Fill in the blank
int factorial(int n) {
return (n<=0?1:_____);
}
What is factorial(n-1)*n
execute a block of statements continuously until the given condition is true, and the condition is checked after the statements are executed
Do while
allows a class to have more than one method with the same name, but with different parameters
Overloading
what is 10101010 in decimal
170
what does this do
public String startOz(String str) {
return (str.length() > 1 ? str.substring(0,1).equals("o") ? str.substring(1,2).equals("z") ? "oz" : "o" : str.substring(1,2).equals("z") ? "z" : "" : str);
}
Given a string, return a string made of the first 2 chars (if present), however include first char only if it is 'o' and include the second only if it is 'z', so "ozymandias" yields "oz".
Given a string str, if the string starts with "f" return "Fizz". If the string ends with "b" return "Buzz". If both the "f" and "b" conditions are true, return "FizzBuzz". In all other cases, return the string unchanged
Fill in the blank
String tstr = str.substring(0,1).equals("f") ? "Fizz" : "";
tstr += str.substring(_________? "Buzz" : "";
return(tstr.equals("") ? str : tstr);
str.length()-1,str.length()).equals("b")
predefined programming definition of methods and variables in a Java class
Abstract
What is oop
a computer programming model that organizes software design around data, or objects, rather than functions and logic.
what is 234156798 as a decimal
234156798
what does this do
public int strCount(String str, String sub) {
if(str.length() < sub.length())
return 0;
else if(str.substring(0, sub.length()).equals(sub))
return 1 + strCount(str.substring(sub.length()), sub);
else return strCount(str.substring(1), sub);
}
Given a string and a non-empty substring sub, compute recursively the number of times that sub appears in the string, without the sub strings overlapping.