Task 3 of 7 · 0 solved · 7 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

3.3 Methods — using the returned value

Lesson

Doing something with the result

A returned value is just a value — you can store it in a variable, use it inside a bigger expression, print it, or pass it straight to another method. Wherever a value of that type fits, a method call that returns it fits too.


Worked example

// square(int n) returns n * n
int r = square(5);            // store it: r is 25
System.out.println(r + 1);    // use it in math: 26
System.out.println(square(2) * square(3));  // 4 * 9 = 36

▶ Try it: run this — the returned values are stored and combined. Change the numbers and re-run.



square returns n * n. What does this print?

int x = square(3);
System.out.println(x + 1);

square returns n * n. Type what this prints:

System.out.println(square(2) * square(3));

A value returned by a method can be...


True or false?