public static void hello() { //①
System.out.println("Hello") //②
① Statement of important matters (method name is hello
)
② Processing content
public static void main(String[] args) {
System.out.println("Call the method");
hello("A");
hello("B");
hello("C");
System.out.println("The method call is finished");
}
public static void hello(String name) {
System.out.println(name + "Kun, Hello");
}
① Pass A, B, C and call the hello method (2) String variable: Declare name ③ Actual argument: A.B.C Formal argument: name ** Actual display ** A-kun, Hello B-kun, Hello C-kun, Hello
If nothing is passed: Method name ()
When passing one value: Method name (value)
When passing multiple values: Method name (value, value, ...)
(In case of multiple, use by separating with comma,
)
return Return value;
** Notes on return statement ** It also terminates the method. Even if you write a process after the return statement, it will not be executed.
Recommended Posts