75_带参数方法练习

 1 package com_01;
 2 /*
 3     需求:
 4         设计一个方法用于打印两个数中的较大数
 5 
 6      思路:
 7         1.定义一个方法,用于打印两个数字中的较大数,例如getMax()
 8         2.方法中定义两个变量,用于保存两个数字
 9         3.使用分支语句分两种情况对两个数字的大小关系进行处理
10         4.在main()方法中调用定义好的方法(使用常量)
11         5.在main()方法中调用定义好的方法(使用变量)
12  */
13 public class MyMethodNumber01 {
14     public static void main(String[] args) {
15         getMax(10,20);
16 
17         int a = 10;
18         int b = 20;
19         getMax(a,b);
20 
21     }
22     //定义一个方法,用于打印两个数字中的较大数,例如getMax()
23     public static void getMax(int a, int b){
24 
25         //使用分支语句分两种情况对两个数字的大小关系进行处理
26         if(a > b){
27             System.out.println(a);
28         }else{
29             System.out.println(b);
30         }
31     }
32 }

 

posted @ 2020-11-23 22:00  找不到北的北  阅读(83)  评论(0)    收藏  举报