import java.io.*;
class ArrayB
{
private int a;
private boolean b=true;
public Object setA;
public int getA()
{
return a;
}
public boolean getB()
{
return b;
}
public void alterB()
{
b=false;
}
public void setA(int m)
{
a=m;
}
}
public class Test 
{


public static void main(String [] args) throws NumberFormatException, IOException
{
ArrayB [] array=new ArrayB[10];
int counts2=0;
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<10;i++)
{
System.out.println("请输入");
array[i].setA(Integer.parseInt(input.readLine()));

}
double [] array2 = new double [10];
for (int j = 0; j<=9&&array[j].getB(); j++)
{
int counts1 = 0;
for (int z = 0; z<=9; z++)
{
/*if(array[j].getA() == array[z].getA())
{
counts1++;
}*/
if(array[j].getA() == array[z].getA()&&j!=z)
{
counts1++;
array[z].alterB();
}
}

array2[counts2] = array[j].getA();
counts2++;


//创建数组3,以提取出的数值的个数为其数组容量,并将提取值依次赋值于其。
double [] array3 = new double [counts2];
for ( int f = 0; f<counts2; f++)
{
array3 [f] = array2 [f];
System.out.println(array[f].getA());
}
}
}
//2  6 9 4 8 4 4 5 5 7
//2  6 9 8 7 4 4 5 5 7

解决方案 »

  1.   

    在System.out.println("请输入");
    array[i].setA(Integer.parseInt(input.readLine()));
    之间插入
    array[i] = new ArrayB();
    原因不用分析吧?
      

  2.   

    应该报的是NullPointException
    同意楼上,数组初始化之后默认都是Null, 必须创建对象才能赋值public static void main(String [] args) throws NumberFormatException, IOException
    {
    ArrayB [] array=new ArrayB[10];
    int counts2=0;
    BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
    for(int i=0;i<10;i++)
    {
    System.out.println("请输入");
    //修改。。
    array[i] = new ArrayB();
    array[i].setA(Integer.parseInt(input.readLine()));}