package java_2;
public class MaxDemo {
public void max(float a, float b){
float max;
if(a>b){
max = a;
}else{
max = b;
}
System.out.println(a+"和"+b+"中最大值为:"+max);
}
public static void main(String[] args){
MaxDemo num = new MaxDemo();
int a = 5, b = 7;
num.max(a, b);
float m = 5.7f, n = 9.7f;
num.max(m, n);
num.max(9.4f, 5.3f);
}
}
输出:
5.0和7.0中最大值为:7.0
5.7和9.7中最大值为:9.7
9.4和5.3中最大值为:9.4