冒泡排序Java数组应用

Java冒泡排序代码示例:
int [] arr={2,4,3,6,5,1,9,8};
          for ( int i=0;i length -1;i++){
              for ( int j=0;j length -i-1;j++){
                  int temp=0;
                  if (arr[j]>arr[j+1]){   //升序排列大于号,降序排列小于号
                      temp=arr[j+1];
                      arr[j+1]=arr[j];
                      arr[j]=temp;
                 }
             }
         }
         System. out .println(Arrays. toString (arr));

你可能感兴趣的:(Java基础)