//从键盘输入三个数,并对他们进行从小到大的排列 //引入数据获取的类 import java.util.Scanner; class Test2 { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("请输入三个数:"); int m1=s.nextInt(); int m2=s.nextInt(); int m3=s.nextInt(); int max=(m1>m2)?m1:(m2>m3)?m2:m3; if(max==m1){ if(m2>m3){ System.out.println(m3+"\t"+m2+ "\t"+m1); } else{ System.out.println(m2+ "\t" +m3+ "\t" +m1); } }else if(max==m2){ if(m1>m3){ System.out.println(m3+ "\t" +m1+ "\t" +m2); } else { System.out.println(m1+ "\t" +m3+ "\t" +m2); } }else{ //else后面不能跟条件 if(m1>m2){ System.out.println(m2+ "\t" +m1+ "\t" +m3); }else{ System.out.println(m1+ "\t" +m2+ "\t" +m3); } } } }
时间: 2024-10-08 07:48:11