哪位贵友帮我解决一些JAVA题?谢谢!

来源:百度知道 编辑:UC知道 时间:2024/05/15 17:55:23
使用Java.lang.Math类,生成100个0到99之间的随机整数,采用选择法对他们进行排序,排序前后都要进行输出。

改的好,我是为了让他看明白!
public class Ran{
private static int[] array = new int[100];
public void getM() {
int i = 1;
array[0] = (int) (Math.random() * 100) + 1;
while (i < 100) {
int count = 0;
int now = i;
array[i] = (int) (Math.random() * 100 + 1);
for (int j = 0; j < now; j++) {
if (array[i] != array[j])
count++;
if (count == i)
i++;
}
}
System.out.println("排序前:");
for (int j = 0; j < 100; j++)
System.out.print(array[j] + ",");
}
Ran(int[] array) {
this.array = array;
}
public void select() {
int index;
for (int i = 0; i < array.length; i++) {
index = 0;
for (int j = 0; j < array.length - i; j++) {
if (array[j] > array[index]) {
index = j;
}
}
int tem = array[index];
array[index] = array[array.leng