zoukankan      html  css  js  c++  java
  • JAVA编程---------28、对10个数进行排序(冒泡排序)

     1 package FushiExam;
     2 import java.util.*;
     3 public class Text_28 {
     4 
     5     public static void main(String[] args) {
     6         // 对10个数进行排序(冒泡排序)
     7         Scanner scan=new Scanner(System.in);
     8         int [] arr=new int[10];
     9         for(int k=0;k<10;k++) {
    10             arr[k]=scan.nextInt();
    11         }
    12         for(int i=arr.length-1;i>0;i--) {
    13             for(int j=0;j<i;j++) {
    14                 if(arr[j]>arr[j+1])
    15                     swap(arr,j,j+1);
    16             }
    17         }
    18         System.out.println("排序后结果:");
    19         for(int m=0;m<arr.length;m++) {
    20             System.out.print(" "+arr[m]);
    21         }
    22         }
    23     public static void swap(int arr[],int i,int j) {//交换数组在数组中交换才可以实现
    24         int t=arr[i];
    25         arr[i]=arr[j];
    26         arr[j]=t;
    27     }
    28 
    29 }
  • 相关阅读:
    很难理解的三个设计模式
    设计模式思考(转)
    AOP
    CAP理论(摘)
    DDBS
    NoSql
    Enterprise Library 企业库
    padright padleft
    Process ProcessThread Thread
    053374
  • 原文地址:https://www.cnblogs.com/fmust/p/12508759.html
Copyright © 2011-2022 走看看