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
解决方案 »
- 大学里没有过英语4,6级 出去能做程序员的不?
- 针对每过5分钟的一次数据发送,Socket保持长短连接的选择
- [求助]这是为什么?为什么?
- java如何实现界面的中英文转换?
- 有要请教大家,真是不好意思,是关于applet和jsp的!!!!!
- 在Intellij IDEA中如何调用swing explorer插件
- 今天以96通过SCJP考试(含考试经验和部分真题)
- 很奇怪的关于socket和IO流的问题,大家都来看啊……
- 为什么我调用image的getWidth和getHeight时总是出错?
- 一般WEB应用, 多久进行一次FULL GC算是正常的?
- 怎么配置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()));}