0
0
Javaprogramming~15 mins

Return values in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return the sum of two numbers.

Java
public int add(int a, int b) {
    return a [1] b;
}
🎯 Drag options to blanks, or click blank then click option
A+
B-
C*
D/
Attempts:
3 left
2fill in blank
medium

Complete the method to return the length of the input string.

Java
public int getLength(String text) {
    return text.[1]();
}
🎯 Drag options to blanks, or click blank then click option
Asize
BlengthOf
Clength
Dcount
Attempts:
3 left
3fill in blank
hard

Fix the error in the method to correctly return the maximum of two numbers.

Java
public int max(int x, int y) {
    if (x > y) {
        return [1];
    } else {
        return y;
    }
}
🎯 Drag options to blanks, or click blank then click option
Ay
B0
Cx + y
Dx
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a method that returns true if a number is even.

Java
public boolean isEven(int num) {
    return num [1] 2 [2] 0;
}
🎯 Drag options to blanks, or click blank then click option
A%
B==
C!=
D/
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a method that returns a new string with the first letter capitalized.

Java
public String capitalize(String word) {
    return word.[1](0, 1).[2]() + word.[3](1);
}
🎯 Drag options to blanks, or click blank then click option
Asubstring
BtoUpperCase
DtoLowerCase
Attempts:
3 left