蓝桥杯 之 算法训练 排序
        【摘要】     问题描述   编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。   输入格式:输入只有一行,即三个整数,中间用空格隔开。   输出格式:输出只有一行,即排序后的结果。   输入输出样例  样例输入 9 2 30 
样例输出 30 9 2 
 
import java.util.Scanner;
public class Main {
		pu...
    
    
    
    问题描述
   编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。
   输入格式:输入只有一行,即三个整数,中间用空格隔开。
   输出格式:输出只有一行,即排序后的结果。
  
 输入输出样例 
 样例输入
 9 2 30
样例输出
 30 9 2
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; }
		}
}
  
 - 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28

文章来源: czhenya.blog.csdn.net,作者:陈言必行,版权归原作者所有,如需转载,请联系作者。
原文链接:czhenya.blog.csdn.net/article/details/104901665
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)