【发布时间】:2014-04-01 15:57:30
【问题描述】:
这是作业 1。
现在我必须创建相同的东西,但使用一个包含 1-100 个值的随机数组,我不知道如何将它实现到我已经拥有的东西中。
public class Test {
public static void main(String a[]) {
int i;
int[] array = {9,1,5,8,7,2,1,5,5,6,8,15,3,9,19,18,88,10,1,100,4,8};
System.out.println("Values Before the sort:\n");
for (i = 0; i < array.length; i++)
System.out.print(array[i] + " ");
System.out.println();
bubble_srt(array, array.length);
System.out.print("Values after the sort:\n");
for (i = 0; i < array.length; i++)
System.out.print(array[i] + " ");
System.out.println();
}
public static void bubble_srt(int a[], int n) {
int i, j, t = 0;
for (i = 0; i < n; i++) {
for (j = 1; j < (n - i); j++) {
if (a[j - 1] > a[j]) {
t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
}
}
}
}
【问题讨论】:
-
查看
Random类。 -
如@ZouZou所说,使用
Random类为你生成100个随机值。 -
欢迎来到 SO。开发人员(或任何人,真的)可以拥有的最重要的技能是了解如何在 Google 上查找内容。如果您在 Google 中输入“java random”,您将获得数千次点击,第一页上有大量有用的信息。
标签: java random bubble-sort