描述
使用方法实现加减乘除,要求重载
输入数据
无
输出结果
输出加减乘除的结果
package com.study.day0107;
public class MyJava1 {
public static void main(String[] args) {
System.out.println(add(2,3));
System.out.println(add(4,6,9));
System.out.println(sub(7,12));
System.out.println(mul(3,7));
System.out.println(div(3,9));
}
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;
}
public static int sub(int a,int b){
if (a>b){
return a-b;
}else{
return b-a;
}
}
public static int mul(int a,int b){
return a*b;
}
public static double div(int a,int b){
if(a==0 || b==0){
return -1;
}
else{
return a/b;
}
}
}
|