数组冒泡排序
2016-04-12 22:57
459 查看
package com.heima.test; import java.util.Random; public class Test17 { /**数组冒泡排序 * @param args */ public static void main(String[] args) { int [] arr = getArray(); sort(arr); print(arr); } public static void print(int[] arr) { for(int i = 0;i < arr.length;i++){ System.out.print(arr[i]+" "); } } private static void sort(int[] 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]){ int temp; temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } public static int[] getArray() { int []arr = new int[10]; Random r = new Random(); for(int i = 0;i < 10;i++){ int num = r.nextInt(60)+1; arr[i] = num; } return arr; } }
相关文章推荐
- 文件递归改后缀
- CollapsingToolbarLayout的使用
- 【每周一文】Ad Click Prediction: a View from the Trenches(2013)
- 自动轮播图(可以有点击事件的其中点击事件用 block 传值)
- 结构化开发方法和面向对象开发方法
- Hibernate单向一对多关联
- 文件夹按层级打印
- 键盘接收2个文件路径,将一个 拷贝到另一个中
- 删除一个文件夹
- 【每周一文】Learning Classifiers from Only Positive and Unlabeled Data(2008)
- ObjectAttribute.js
- JAVA多线程学习(一)
- Mongodb 聚合管道
- 统计一个文件夹的大小
- 声明一个共享数组,起两个线程,两个线程分别隔一段时间(可以写一个随机数),给数组中 添加数据,每一个线程为数组添加 3 个数据即可。
- win7 下anaconda 安装及安装包
- 《麦田里的守望者》感
- 【每周一文】Building Text Classifiers Using Positive and Unlabeled Examples(2003)
- 取出一个字符串中字母出现的次数。如:字符串:"abcdekka27qoq" ,输出格式为: a(2)b(1)k(2)
- View的事件体系---V3.1 View基础知识