02、方法的定义和调用

在这里插入图片描述
在这里插入图片描述

package com.wzt.www.method;

/**
 * @author WZT
 * @create 2021-03-26 9:47
 */
public class Demo02 {
    
    
    public static void main(String[] args) {
    
    
        int max = max(10, 10);
        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;//注意:return 0 可以直接结束该方法,return 0 之后不可以再写代码了
        }
        else if (num1>num2){
    
    
                result = num1;
            }
        else if (num1<num2){
    
    
                result = num2;
            }
        return result;
    }
}

输出

num1=num2
0

Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/weixin_45809838/article/details/115228582