输入两个数,比较其大小
public static void main(String[] args) {
System.out.println("请输入两个数字:");
Scanner s1 = new Scanner(System.in);
int num1 = s1.nextInt();
int num2 = s1.nextInt();
int max1 = max(num1,num2);
System.out.println(max1);
s1.close();
}
//比大小
public static int max(int num1,int num2){
int result = -1;
if(num1 > num2){
result = num1;
}else if(num1 < num2){
result = num2;
}else{
System.out.println("相等");
return 0;
}
return result;
}
输出结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)