L1-010. 比较大小

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);  //全相等
		}

	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值