Blue Bridge Cup training sorting algorithm

Description of the problem
  to write a program, input three integers, then the program will be arranged according to the three largest to smallest integer.
  Input format: input single line, i.e. three integers, separated by a space.
  Output formats: Output only one line, that is the result of the sort.

 
   Sample input and output  
sample input
9230

Sample output
3092



import java.util.Scanner;

public class Main {
		public static void main(String[] args) {
			Scanner sc=new Scanner(System.in);
			int[] shuzu=new int[3];
			for(int i=0;i<3;i++){
			shuzu[i]=sc.nextInt();
			}
			f(shuzu);
			for(int i=0;i<3;i++){
				System.out.print(shuzu[i]+" ");
			}
		}
		public static void f(int[] a){
			int i,j,temp;
			for(i=0;i<a.length;i++){
				j=i-1;
				temp=a[i];
				while(j>=0 && temp>=a[j]){
					a[j+1]=a[j];
					j--;
				}
				a[j+1]=temp;					
			}
		}
}

test

Published 475 original articles · won praise 682 · views 520 000 +

Guess you like

Origin blog.csdn.net/Czhenya/article/details/104901665