06 Ch03 1 Parameters
06 Ch03 1 Parameters
Chapter 3
Lecture 3-1: Parameters
reading: 3.1
self-check: #1-6
exercises: #1-3
videos: Ch. 3 #1
To Do
Bake 20 cookies
Take a nap
Bake 40 cookies
Take a walk
Bake 27 cookies
Our hope:
public static void line() {
for (int i = 1; i <= N ; i++) {
System.out.print("*");
}
System.out.println();
}
7
main line *******
13 line *************
Example:
public static void sayPassword(int code) {
System.out.println("The password is: " + code);
}
name (expression);
Example:
public static void main(String[] args) {
sayPassword(42);
sayPassword(12345);
}
Output:
The password is 42
The password is 12345
Output:
Just a salad...
Just a salad...
Just a salad...
Declaration:
public static void name (type name, ..., type name) {
statement(s);
}
Call:
methodName (value, value, ..., value);
Output:
444444444
171717171717
00000000
mystery(z, y, x);
mystery(y, x, z);
}
Examples:
String name = "Toucan Sam";
int x = 3;
int y = 5;
String point = "(" + x + ", " + y + ")";
Output:
Welcome, Kelsey
Welcome, Steve
...