今日对简单数组进行计算
import java.util.Random;
public class maopao {
//生成随即数组;
public static void main(String[] args) {
int[] arr = new int[10];
generateNumber(arr);
for (int temp : arr)
System.out.print(temp + "\t");
System.out.println();
bubble(arr);
for (int temp : arr)
System.out.print(temp + "\t");
System.out.println();
}
public static void bubble(int[] arr) {
for (int k = 1; k < arr.length; k++) {
for (int i = 0; i < arr.length - k; i++) {
if (arr[i] > arr[i+1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
}
public static void generateNumber(int[] arr) {
Random r = new Random();
for (int i = 0; i < arr.length; i++) {
arr[i] = r.nextInt(100);
}
}
}