• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

包com . cheshi . test 2;

导入Java . util . arrays;

公共类ArrayDemo07 {

公共静态void main(String[] args) {

int[] a={1,4,5,6,3,89,67 };

int[]sort=sort(a);//调用自己写的排序方法后,返回一个排序后的数组。

system . out . println(arrays . tostring(a));

}

//冒泡排序

//1,比较数组中两个相邻的元素。如果第一个比第二个大,我们就交换位置。

//2,每次比较都会产生一个最大或最小的数;

//3,下一轮可以少排序一次。

//4,依次排序,直到最后

public static int[]sort(int[]array){

//临时变量

int temp=0;

//外循环,判断这个我们要走多少次

for(int I=0;I array . length-1;i ){

//内循环,比较判断两个数,如果第一个数大于第二个数,交换位置。

for(int j=0;jarray . length-1-I;j ){

if(array[j 1]array[j]){

temp=array[j];

array[j]=array[j 1];

array[j 1]=temp;

}

}

}

返回数组;//循环结束时,将返回方法数组返回数组名。

}

}

Link to comment
Share on other sites