Complete this Code
Reserved Words
Java basics
Binary
Hard Questions
100

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

100

This keyword is used to refer to a parent object

super

100

What is a class

All Java codes are defined in a Class. It has variables and methods.

100

what is 1001 as a decimal

9

100

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.

200

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

200

specifies a block of Java code to be executed if a condition is false in an if statement

Else

200

make an array that is 10 ints long

int [] = new int[10]'

200

what is 27 in binary

11011

200

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.

300

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

300

To access the interface methods, the interface must be _______

implements

300

What is an Object?

An instance of a class is called an object. The object has state and behavior.

300

what is 2048 in binary

100000000000

300

what is 2341567981 in binary

10001011100100010111110111101101

400

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

400

execute a block of statements continuously until the given condition is true, and the condition is checked after the statements are executed

Do while

400

allows a class to have more than one method with the same name, but with different parameters

Overloading

400

what is 10101010 in decimal

170

400

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".

500

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")

500

predefined programming definition of methods and variables in a Java class

Abstract

500

What is oop

a computer programming model that organizes software design around data, or objects, rather than functions and logic.

500

what is 234156798 as a decimal

234156798

500

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.

M
e
n
u