import java
.util
.Scanner
;
public class Main
{
public static void main(String
[] args
)
{
Scanner sc
=new Scanner(System
.in
);
int a
=sc
.nextInt();
int b
=sc
.nextInt();
int c
=sc
.nextInt();
int t
;
if(a
>b
)
{
t
=b
;
b
=a
;
a
=t
;
}
if(a
>c
)
{
t
=c
;
c
=a
;
a
=t
;
}
if(b
>c
)
{
t
=c
;
c
=b
;
b
=t
;
}
System
.out
.println(a
+" "+b
+" "+c
);
}
}
我是新手,代码还很幼稚,如果有更好的改进,请告诉我。
这道题需要从小到大输出, 所以只要把最大的交给c,最小的交给a就行了。 写的时候, 我在想这三个if语句是否可以随意调换, 我想是可以的, 无论如何调换最后都可以保证a<b<c.