package com.jiemyx.method;
public class Demo01 {
//main方法
//public static是修饰符,void空的意思,不返回值
public static void main(String[] args) {
//实际参数:实际调用传递给它的参数
int sum = add(1, 2);
System.out.println(sum);
int sum2 = add(1,2,3);
System.out.println(sum2);
}
//加法方法
//形式参数,用来定义作用的
public static int add(int a,int b){
return a+b;
}
//方法的重载
public static int add(int a,int b,int c){
return a+b+c;
}
}
package com.jiemyx.method;
public class Demo02 {
public static void main(String[] args) {
int max1 = max(10,10);
System.out.println(max1);
System.out.println("============");
//方法的重载
double max2 = max(0.6,0.5);
System.out.println(max2);
}
//比大小
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;
}
//方法的重载
public static double max(double num1,double num2){
double result = 0;
if (num1==num2){
System.out.println("num1==num2");
return 0; //终止方法
}
if (num1>num2){
result = num1;
}else {
result = num2;
}
return result;
}
}
原文:https://www.cnblogs.com/Jiemyx/p/14583953.html