定义一个方法能够判断并返回两个整数的最大值,并调用自己的方法测试是否正确。
(一)
public class p16 {
public static int max(int x,int y) {
int max;
if(x>y){
max=x;
}
else{
max=y;
}
return max;
}
public static void main(String[] args) {
int max= max(25, 18);//一
System.out.println(max); //二
// 一二两部或者写为 System.out.println(max(25,18));
}
}
(二)
public class p16 {
public static void max(int a ,int b ){
if (a>b) {
System.out.println(a);