作业帮 > 综合 > 作业

用java 输入三个整数 按从小到大的顺序排列这三个整数

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 05:48:03
用java 输入三个整数 按从小到大的顺序排列这三个整数
那我给你一个用控制语句语句写的
public class Sort{
public static void main(String args[]){
Scanner in= new Scanner(System.in);
System.out.println("请输入3个整数:");
int a,b,c;
int max,other1,other2;
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
if(a>b&&a>c){
max=a;
other1=b;
other2=c;
}
else if(b>a&&b>c){
max=b;
other1=a;
other2=c;
}
else{
max=c;other1=a;other2=b
}
iif(other1>other2){
System.out.println(other2);
System.out.println(other1);
}
System.out.println(max);
}
}直接在网页上写的,你看看吧,希望你明白