java方法定义使用

定义方法及注意事项

package com.daxing.method;


public class Demo02 {
   public static void main(String[] args) {

       int max=max(20,20);
       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除了返回值以外,还有终止方法功能
      }
       if(num1>num2){
           result=num1;
      }else {
           result = num2;
      }
       return result;//终止方法
  }
}

注意:java是值传递



posted @ 2022-01-24 19:05  狂神大鑫  阅读(28)  评论(0)    收藏  举报