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
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
解决方案 »
- 什么叫做类方法??有什么特征?java类方法可以直接被类调用么??
- JAVA虚拟机
- 关于 Swing 中下拉菜单类和复选框??????????????在线等
- “.newInstance()”产生的错误,求助!!
- 在java中想通过双引号来区分,怎么样写啊?
- 关于JAR文件……
- applet如何得到一个字符串上最后一个字符的坐标
- 500分
- 那位兄弟知道joc.jar的用法呀
- 试用Java 7 的ForkJoin框架写了一个超级简单小例子,运行抛出异常,求高手给看看
- 怎么配置smtp服务器
- Exception in thread "main" java.lang.NullPointerException
array[i].setA(Integer.parseInt(input.readLine()));
之间插入
array[i] = new ArrayB();
原因不用分析吧?
同意楼上,数组初始化之后默认都是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()));}