L1-010. 比较大小
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
杨起帆(浙江大学城市学院)
本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:4 2 8输出样例:
2->4->8
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a < b && a < c) {
System.out.print(a + "->");
if (b < c) {
System.out.print(b + "->");
System.out.print(c);
} else {
System.out.print(c + "->");
System.out.print(b);
}
} else if (b < a && b < c) {
System.out.print(b + "->");
if (a < c) {
System.out.print(a + "->");
System.out.print(c);
} else {
System.out.print(c + "->");
System.out.print(a);
}
} else if (c < a && c < b) {
System.out.print(c + "->");
if (a < b) {
System.out.print(a + "->");
System.out.print(b);
} else {
System.out.print(b + "->");
System.out.print(a);
}
} else if (a == b && a == c) {
System.out.println(a + "->" + a + "->" + a); //全相等
}
}
}