package com.study.month8.job07;
import java.util.ArrayList;
import java.util.Random;
/*1.向list集合中存储10个1-100之间的随机数.要求元素不能重复.
2.使用冒泡排序把集合中的元素按照从小到大排序.
3.使用带索引的for循环遍历集合输出元素.*/
public class job02 {
public static void main(String[] args) {
Random r = new Random();
ArrayList<Integer> arrayList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
arrayList.add(r.nextInt(100) + 1);
}
System.out.println(arrayList);
System.out.println("-----------------");
show(arrayList);
getarr(arrayList);
}
private static void getarr(ArrayList<Integer> arrayList) {
for (int i = 0; i < arrayList.size(); i++) {
System.out.print(arrayList.get(i) + ", ");
}
System.out.println();
System.out.println("-------------------------------");
}
public static void show(ArrayList<Integer> arrayList) {
for (int i = 0; i < arrayList.size(); i++) {
for (int j = i + 1; j < arrayList.size(); j++) {
Integer num = 0;
if (arrayList.get(i) > arrayList.get(j)) {
num = arrayList.get(i);
arrayList.set(i, arrayList.get(j));
arrayList.set(j, num);
}
}
}
System.out.println(arrayList);
System.out.println("----------------------");
}
}