java定义一个实现常用数学运算的类MyMath,类中提供max().min().sum()与average()

2025-01-06 05:35:59
推荐回答(2个)
回答1:

public class MyMath{

private static void max(int x,int y,int z){
if(x>y){
if(x>z){
System.out.println("最大数是X:"+x);
}
else{
System.out.println("最大数是Z:"+z);
}
}
else{
if(y>z){
System.out.println("最大数是y:"+y);
}
else{
System.out.println("最大数是Z:"+z);
}
}
}

private static void min(int x,int y,int z){
if(x System.out.println("最小数是X:"+x);
}
if(y System.out.println("最小数是y:"+y);
}
if(z System.out.println("最小数是y:"+y);
}
}

private static void sum(int x,int y,int z){
int h=x+y+z;
System.out.println("x,y,z的总和为:"+h);
}

private static void average(int x,int y,int z){
int h=x+y+z;
double a=h/3;
System.out.println("x,y,z的平均为:"+a);
}

public static void main(String[] args) {
int x=2;
int y=3;
int z=4;
max(x,y,z);
min(x,y,z);
sum(x,y,z);
average(x, y, z);
}
}

回答2:

public static void main(String []a){
System.out.println(