0
我必须编写一个气泡排序程序,并将它编码出来,但出于某种原因,我的输出完全是疯了。这是一些输出...列表一直到190重复同样的事情; “[I @ 5b787144”使用随机生成的数组进行气泡排序
49, 21, 45, 22, 28, 55, 91, 34, 69, 27, 40, 60, 41, 14, 45, 79, 93, 11, 89, 77, 1)[[email protected]
2)[[email protected]
3)[[email protected]
这是我的代码。
import java.util.Random;
public class Bubble
{
public void generate()
{
int k;
int a[];
int count = 1;
a = new int[20];
for (int i = 0; i < 20; i++)
{
Random rand = new Random();
a[i] = rand.nextInt(100);
System.out.print(a[i] +", ");
}
for (int h = 0; h < a.length-1; h++)
{
for (int j = 1; j < a.length-h; j++)
{
if (a[j-1] > a[j])
{
k = a[j-1];
a[j-1] = a[j];
a[j] = k;
}
System.out.println(+count+ ")" +a);
count++;
}
}
}
}
我需要它按升序排序它,同时打印出的那种每次迭代。
退房[Arrays.toString() ](https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#toString(INT [])) – BevynQ