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.2 Methods — several parameters

Lesson

More than one parameter

A method can take several parameters, separated by commas. Each argument you pass is matched to a parameter by position — first to first, second to second. So the order of the arguments matters.


Worked example

void minus(int a, int b) {
    System.out.println(a - b);
}

minus(10, 3);   // 7
minus(3, 10);   // -7

Same method, swapped arguments, different result — because a and b are filled by position.


▶ Try it: minus(int a, int b) prints a - b. Run this, then swap the two numbers and re-run — the answer changes sign.



showScore(String p, int pts) prints p, then : , then pts. What does showScore("Ada", 5) print?


minus(int a, int b) prints a - b. What does minus(3, 10) print?


For box(int w, int h) called as box(4, 2), match each parameter to the value it receives.


True or false?


Type exactly what this program prints.

public class Main {
    static void plus(int a, int b) {
        System.out.println(a + b);
    }
    public static void main(String[] args) {
        plus(2, 5);
        plus(5, 2);
    }
}