1
使用随机类获取0到99之间的数字并将它们存储到数组中。使用for循环来获取每个随机数,将每个数存储到数组中,并打印每个值。通过随机类和排序生成数组的数据
然后使用冒泡排序对数组进行排序,并打印出存储的数组。
这里是我的程序
import java.util.Random;
public class Randomness
{
public static void main(String[] args)
{
Random randomNum = new Random();
for (int number = 0; number <= 99; ++number)
{
int num = randomNum.nextInt(100);
System.out.print(num + " ");
int numValues = num;
int [] values = new int[numValues];
boolean swap;
do
{
swap = false;
int temp;
for (int count = 0; count < numValues-1; count++)
if (values[count] > values[count+1])
{
temp = values[count];
values[count] = values[count+1];
values[count+1] = temp;
swap = true;
}
} while (swap);
System.out.print(values[count] + " ");
}
}
}
我得到错误
是System.out.print(值[计] +““);数组需要,但随机发现。
请帮助!
谢谢allot男人我感谢所有的帮助。 是 System.out.print(values [count] +“”); 对不对? 仍然出现错误... 我固定在顶部,你说,像复制,但仍然没有希望。非常感谢帮助我。 –
@AvoKoburyan首先,'count' int在你的System.out.print(values [count] +“”);'line中超出了范围。不知道你是如何得到它的编译。 –