我试图从数组中删除重复项。我在数组大小10([11])上工作。然后我不得不将它扩展到5000([5001])。我认为这会很简单。它编译,但是当我运行它时,它会运行一个无限循环。我不确定它是否需要很长时间或者什么不起作用。 sort.sorting
的作品。删除重复项扩展错误
public class work_on_it5
{
public static void main(String [] args)
{
int array [] = new int [5001];
int LB = 1;//declare the lower bound
int UB = 5000;//declare the upper bound
for(int x = 0; x < 4999; x++)
{
if(array[x]==array[x+1])
{
array[x+1] = (int)(Math.random()*50) + 1;
sort.sorting(array);
x=0;
}
}
sort.sorting(array);
for(int x = 0; x < 4999; x++)
{
System.out.println(array[x]);
}
//median(LB, UB, array);
//mean(array);
}
你的索引是什么?我想这里可能会有一些误解。 'int [5001]'有5001个元素,而不是5000.不知道为什么当x <5000'或更好的时候使用'x <4999',或者更好,'x
Zong