1 package FushiExam; 2 import java.util.*; 3 public class Text_15_1 { 4 5 public static void main(String[] args) { 6 // 输入三个整数x,y,z,请把这三个数由小到大输出 7 //String str=scan.nextLine(); 8 Scanner scan=new Scanner(System.in); 9 int a=scan.nextInt(); 10 int b=scan.nextInt(); 11 int c=scan.nextInt(); 12 int[] arr= {a,b,c}; 13 if(arr[0]>arr[1]) { 14 swap(arr,0,1); 15 } 16 if(arr[0]>arr[2]) { 17 swap(arr,0,2); 18 } 19 if(arr[1]>arr[2]) { 20 swap(arr,1,2); 21 } 22 System.out.println(arr[0]+"<"+arr[1]+"<"+arr[2]); 23 } 24 public static void swap(int[] arr,int i,int j) { 25 int t; 26 t=arr[i]; 27 arr[i]=arr[j]; 28 arr[j]=t; 29 } 30 31 }
代码二:‘
1 package FushiExam; 2 import java.util.*; 3 public class Text_15 { 4 5 public static void main(String[] args) { 6 // 输入三个整数x,y,z,请把这三个数由小到大输出 7 Scanner scan=new Scanner(System.in); 8 int a=scan.nextInt(); 9 int b=scan.nextInt(); 10 int c=scan.nextInt(); 11 int t; 12 if(a>b) { 13 t=a; 14 a=b; 15 b=t; 16 } 17 if(a>c) { 18 t=a; 19 a=c; 20 c=t;} 21 if(b>c) { 22 t=b; 23 b=c; 24 c=t; 25 } 26 System.out.println(a+"<"+b+"<"+c); 27 } 28 29 }