Java入门程序:从控制台输入三个整数,实现按大小顺序输出

java从控制台输入三个整数,实现按大小顺序输出

package test;

import java.util.Scanner;
/* java从控制台输入三个整数,实现按大小顺序输出  */

public class paixu {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入任意三个整数,并以空格隔开,以回车键结束:");
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		scanner.close();
		System.out.println("输入的值为:a = " + a + ",  b = " + b + ", c = " + c);
		if(a > b){
			if ( b > c) {
				System.out.println("按从小到大排序为:" + c + "," + b + "," + a);
				System.out.println("按从大到小排序为:" + a + "," + b + "," + c);
			}else if( c > a){
				System.out.println("按从小到大排序为:" + b + ","  + a + "," + c);
				System.out.println("按从大到小排序为:" + c + "," + a + "," + b);
			}else{
				System.out.println("按从小到大排序为:" + b + "," + c + ","  + a);
				System.out.println("按从大到小排序为:" + a + "," + c + "," + b);
			}
		}else{
			if(c < a){
                System.out.println("按从小到大排序为:" + c + "," + a + "," + b);
                System.out.println("按从大到小排序为:" + b + "," + a + "," + c);
            }else if(c > b){
                System.out.println("按从小到大排序为:" + a + "," + b + "," + c);
                System.out.println("按从大到小排序为:" + c + "," + b + "," + a);
            }else{
                System.out.println("按从小到大排序为:" + a + "," + c + "," + b);
                System.out.println("按从大到小排序为:" + b + "," + c + "," + a);
            }
		}
	}
}

你可能感兴趣的:(Java基础)