黑马程序员技术交流社区

标题: 把三个数由小到大输出 [打印本页]

作者: pathnet    时间: 2015-7-12 16:50
标题: 把三个数由小到大输出
import java.util.Scanner;
public class Prog{
        public static void main(String[] args){
                Scanner scan = new Scanner(System.in).useDelimiter("\\D");
                System.out.print("请输入三个数:");
                int x = scan.nextInt();
                int y = scan.nextInt();
                int z = scan.nextInt();
                scan.close();
                System.out.println("排序结果:"+sort(x,y,z));
        }
        //比较两个数的大小
        private static String sort(int x,int y,int z){
                String s = null;
                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 = z;
                        z = y;
                        y = t;
                }
                s = x+" "+y+" "+z;
                return s;
        }
}

作者: 康恒强    时间: 2015-7-12 17:39
不错不错
作者: xyxlx111    时间: 2015-7-12 22:07
不错,顶一个
作者: 何鹏程    时间: 2015-7-12 22:12
写入方式好啊,真好。
作者: 453203489    时间: 2015-7-12 22:34
善于总结, 赞一个。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2