Java: Method Parameter
Dec 11, 2023
Next after we write a method that used for print string, we actually can make the method run specific task with inputs. The input itself can be any data type, like string, integer, and double. Below code is a method that receive two string input and print it as the part of greeting statement when we called the function.
public class Main {Get Aldyputu’s stories in your inbox
Join Medium for free to get updates from this writer.
static void sayMyName(String firstName, String lastName){
System.out.println("Hello " + firstName + " " + lastName + "!");
}
public static void main(String[] args) {
sayMyName("Ganjar", "Subekti");
}
}
/*
Output
Hello Ganjar Subekti!
*/
Lets write another function with integer input:
public class Main {
static void adding(int oneNum, int secNum){
int sum = oneNum + secNum;
System.out.println(sum);
}
public static void main(String[] args) {
adding(100, 99);
}
}
/*
Output
199
*/



