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.
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.
a
b
▶ Try it: minus(int a, int b) prints a - b. Run this, then swap the two numbers and re-run — the answer changes sign.
minus(int a, int b)
a - b
showScore(String p, int pts) prints p, then : , then pts. What does showScore("Ada", 5) print?
showScore(String p, int pts)
p
:
pts
showScore("Ada", 5)
minus(int a, int b) prints a - b. What does minus(3, 10) print?
minus(3, 10)
For box(int w, int h) called as box(4, 2), match each parameter to the value it receives.
box(int w, int h)
box(4, 2)
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); } }