- /**
- * Created by yikwing on 2016/5/17.
- */
- import java.util.Random;
- public class maopao {
- public static void main(String[] args) {
- long stratTime = System.currentTimeMillis();
- int sum = 0;
- for (int i = 0; i < 1000000000; i++) {
- sum += i;
- }
- Random r = new Random();
- int arr[] = new int[10];
- for (int i = 0; i < arr.length; i++) {
- arr[i] = r.nextInt(100);
- }
- PrintArray(arr);
- 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]) {
- Swap(arr, j, j + 1);
- }
- }
- }
- PrintArray(arr);
- long endtime = System.currentTimeMillis();
- System.out.println("程序运行时间为:" + (endtime - stratTime) + "毫秒");
- }
- public static void PrintArray(int[] arr) {
- for (int i = 0; i < arr.length; i++) {
- System.out.print(arr[i] + " ");
- }
- System.out.println();
- }
- public static void Swap(int[] arr, int i, int j) {
- int temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- }
- }
复制代码 |