https://courses.cs.washington.edu/courses/cse121/.
(a group of statements that runs when called, also reduces redundancy)
public static void name() {
statements;
}
public static void printHello() {
System.out.println("Hello World");
System.out.println("Have a great day!");
System.out.println();
}
methodName();
public static void main(String[] args) {
printHello();
printHello();
}
Hello World
Have a great day!
Hello World
Have a great day!
(unchangeable global values that can be seen within your class
)
public class ClassName() {
...
public static final <type> <name> = <value>;
}
public class Hello() {
...
public static final int DAYS_PER_WEEK = 7;
}
(a way to pass information into a method)
public static void name(type name, ...) {
statements;
}
public static void box(int width, int height) {
for (int i = 1; i <= height; i++) {
for (int j = 1; j <= width; j++) {
System.out.print("*");
}
System.out.println();
}
}
methodName(value, ..., value);
public static void main(String[] args) {
box(10, 7); // width = 10, height = 7
box(5, 3); // width = 5, height = 3
}
**********
**********
**********
**********
**********
**********
**********
*****
*****
*****