public class Test2 {
public static void main(String[] args) {
int [] arr = {12,25,8,63,26,21,15,9,2};
//外层循环控制冒泡的次数
for (int i = 0; i < arr.length-1; i++) {
//内层循环控制每一次冒泡你要判断数
for (int j = 0; j < arr.length-1-i; j++) {
if(arr[j]>arr[j+1]){
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr+" ");
}
}
}
二, 在一个数组中,某一个元素出现的次数>length/2,请用程序获取数组中的该数字。 public static void main(String[] args) {
int[] arr = {1, 0, 1, 0, 0, 3, 1, 0, 0, 8, 0};
int count = 1;
for (int i = 1; i < arr.length; i++) {
if (count == 0) {
winner = arr;
count++;
continue;
}
if(winner == arr){
count++;
}else{
count--;
}
}
System.out.println(winner);
}
}