Java方法之方法调用

学习Demo

  

 

码上行动

   

package TestDemo;

/**
 * 调用方法:对象名.方法名(实参列表)
 */
public class Test1 {

    public static void main(String[] args) {

        int max = max(10, 20); //调用max方法(实参)
        System.out.println(max);

    }

    //比大小
    public static int max(int num1, int num2){ //形参

        int result = 0;

        if (num1 == num2){
            System.out.println("num1 == num2");
            return 0; //终止方法
        }

        if (num1 > num2){
            result = num1;
        }else {
            result = num2;
        }
        return result;
    }
}
View Code
 
posted @ 2020-09-18 14:44  无明之辈  阅读(133)  评论(0编辑  收藏  举报