A parameter is a named input listed in a method's (). It lets one method work on different values: you supply a value when you call it, and the method uses it. That makes a method flexible instead of doing the exact same thing every time.
()
void greet(String name) { System.out.println("Hello, " + name + "!"); } greet("Ada"); // Hello, Ada! greet("Sam"); // Hello, Sam!
The parameter name takes a different value on each call.
name
▶ Try it: greet(String name) is defined for you. Run this, then change the names in the calls (or add more) and re-run.
greet(String name)
greet(String name) prints Hello, then the name then !. What does greet("Sam") print?
Hello,
!
greet("Sam")
In the call greet("Sam"), what is "Sam"?
"Sam"
Fill the blank to call greet with the name Ada.
greet
Ada
A method hi(String name) prints Hi then the name. Type exactly what hi("Bo") prints:
hi(String name)
Hi
hi("Bo")
True or false?