码迷,mamicode.com
首页 > 编程语言 > 详细

Java经典编程题50道之十五

时间:2017-06-03 00:00:12      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:out   输出   system   编程   个数   print   static   class   rgs   

输入三个整数x,y,z,请把这三个数由小到大输出。

public class Example15 {
    public static void main(String[] args) {
        sort(15, 10, 5);
    }

    public static void sort(int x, int y, int z) {
        if (x > y) {
            int t = x;
            x = y;
            y = t;
        }
        if (x > z) {
            int t = x;
            x = z;
            z = t;
        }
        if (y > z) {
            int t = y;
            y = z;
            z = t;
        }
        System.out.println("三个数字由小到大排列为: " + x + " " + y + " " + z);
    }
}

Java经典编程题50道之十五

标签:out   输出   system   编程   个数   print   static   class   rgs   

原文地址:http://www.cnblogs.com/qubo520/p/6935409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!