带参方法(Parametric method)

带参方法定义

public static void getMax(int a,int b){

  //方法体

}

带参方法调用(变量名、常数值)

常数值

getMax(5);

变量名

public class Test {    public static void main(String[] args) {        int number = 10;        getEvenNumber(number);    }    //判断奇偶数    public static void getEvenNumber(int a) {        if (a % 2 == 0) {            System.out.println("偶数");        } else {            System.out.println("奇数");        }    }}

带参方法调用时,参数数量和类型必须和方法定义中的设置相匹配

————————

Definition of method with parameters

public static void getMax(int a,int b){

/ / method body

}

Method call with parameters (variable name, constant value)

Constant value

getMax(5);

Variable name

public class Test {    public static void main(String[] args) {        int number = 10;        getEvenNumber(number);    }    //判断奇偶数    public static void getEvenNumber(int a) {        if (a % 2 == 0) {            System.out.println("偶数");        } else {            System.out.println("奇数");        }    }}

When calling a method with parameters, the number and type of parameters must match the settings in the method definition