Java方法定义和调用(java中方法如何定义)
public class Java03 {
// 自定义方法的角色:实现方法实现功能的人
public static int m1(int c, int d) {
if (c > d) {
System.out.println(c);
return c;
}
System.out.println(d);
return d;
}
// 有返回值的方法:必须有返回值!
public static int m2(){
// 第一步:定义存储结果的变量
int result = 0;
// 第二步:把结果存储到变量中
// 第三步:返回存储结果的变量
return result;
}
public static void main(String[] args) {
// 在主方法中编写代码的角色:用户、使用方法调用方法的人
// 找出2个变量中的最大值?
int a = 2;
int b = 4;
int c = m1(a, b);
System.out.println(c);
}
}