java问题:判断两个数的大小

2025-02-28 13:37:46
推荐回答(5个)
回答1:

import java.util.Scanner;  
public class zuoye03_5_2 {  
    public static void main(String[] args) {  
        Scanner sc=new Scanner(System.in);  
        System.out.println("---->输入两个数(例如20 12):");  
        int max=sc.nextInt();  /*键盘输入*/   
        int min=sc.nextInt();     
        String a;  /*定义变量*/  
        a=(max>min)?"大":"小";  
        System.out.println(a);     /*输出最大值*/     
    }  
}

回答2:

你明显受到了Pascal的影响。函数名不能作为变量回带数值。该为:
public class Alone5_1{
int max(int x,int y){
if(x>y)
return x;
else
return y;
}
public static void main(String[] args){
Alone5_1 xy=new Alone5_1();
System.out.println("max(10,20) >= "+ xy.max(10,20));

}
}

回答3:

一楼说的很对,其实那样是没返回值得!另外,判断条件那最好改成:

if(x>y)
{return x; }
else
{return y; }

回答4:

最近发现好多转语言的人啊。

回答5:

楼上说的对