java程序实现对三个整数排序源码答案
本题要求采用非降序的形式显示这三个整数,所以我们采用升序来进行排列。package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter there numbers in int,for example 2 3 1:"); int number1=input.nextInt(); int number2=input.nextInt(); int number3=input.nextInt(); if(number1>number2&&number1>number3){ if(number2>number3){ System.out.println(number3+" "+number2+" "+number1); } else System.out.println(number2+" "+number3+" "+number1); } else if(number2>number1&&number2>number3){ if(number1>number3){ System.out.println(number3+" "+number1+" "+number2); } else System.out.println(number1+" "+number3+" "+number2); } else if(number3>number1&&number3>number2){ if(number1>number2){ System.out.println(number2+" "+number1+" "+number3); } else System.out.println(number1+" "+number2+" "+number3); } }
页:
[1]