Complete the code to return the sum of two numbers.
public int add(int a, int b) {
return a [1] b;
}The return statement must return the sum of a and b. The plus sign + adds two numbers.
Complete the method to return the length of the input string.
public int getLength(String text) {
return text.[1]();
}size() which is for collections, not strings.count().The method length() returns the number of characters in a string in Java.
Fix the error in the method to correctly return the maximum of two numbers.
public int max(int x, int y) { if (x > y) { return [1]; } else { return y; } }
If x is greater than y, the method should return x. Returning y here would be incorrect.
Fill both blanks to create a method that returns true if a number is even.
public boolean isEven(int num) {
return num [1] 2 [2] 0;
}/ instead of modulo %.!= instead of equality ==.The modulo operator % gives the remainder. If num % 2 == 0, the number is even.
Fill all three blanks to create a method that returns a new string with the first letter capitalized.
public String capitalize(String word) {
return word.[1](0, 1).[2]() + word.[3](1);
}toLowerCase() instead of toUpperCase().substring.The method takes the first letter with substring(0, 1), converts it to uppercase with toUpperCase(), then adds the rest of the word starting from index 1 with substring(1).
