Computing the return value
The returned value is usually calculated, often from the parameters:
public class Main {
public static void main(String[] args) {
int area = rectangleArea(4, 3);
System.out.println("Area: " + area);
System.out.println("Two rooms: " + (rectangleArea(4, 3) + rectangleArea(5, 2)));
}
public static int rectangleArea(int width, int height) {
int area = width * height;
return area;
}
}
Area: 12
Two rooms: 22return can give back any expression of the right type: return width * height; would do the same without the variable.
A method that returns its result, instead of printing it, is more useful: the caller decides what to do with the value, whether that's printing it, adding it to something or comparing it. rectangleArea works for one room, for two, or in a loop over a whole house.
The checks in this step print what your method returns. If the method also prints something itself, that extra output makes the check fail, so leave the printing to the caller.