JAVA-带参数方法输出较大值

package com.itheima;

//定义带参数的方法,取较大值
public class methodmedo04 {
    public static void main(String[] args) {

        //定义两个变量用于存储数据
        int x = 10;
        int y = 20;
        //在main()方法中引用定义好的方法
        getmax(x, y);
        //实参传入字面量调用方法
        getmax(30, 40);
    }

    //定义一个方法getmax()
    public static void getmax(int a, int b) {

        //通过if语句判断两个值的大小
        if (a > b) {
            System.out.println("较大的数是" + a);
        } else {
            System.out.println("较大的数是" + b);
        }

    }

}

posted @ 2022-08-02 00:01  NiceTwocu  阅读(52)  评论(0编辑  收藏  举报