Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java数组中增加单个值_Java_Arrays - Fatal编程技术网

在Java数组中增加单个值

在Java数组中增加单个值,java,arrays,Java,Arrays,我想知道如何增加数组中的某些索引 int indexArrayHIS[] = new int[15]; int indexArrayFIX[] = new int[20]; indexArrayHIS[]是一个由索引值组成的数组: 69171910616160107118616810 我想用每个索引实例的编号填充indexArrayFIX[]。例如,有2个“9”,因此在indexArrayFIX[]的索引9处,我想显示一个2: indexArrayFIX[]应输出: 2 2 0 0 0 1 1

我想知道如何增加数组中的某些索引

int indexArrayHIS[] = new int[15];
int indexArrayFIX[] = new int[20];
indexArrayHIS[]
是一个由索引值组成的数组: 69171910616160107118616810

我想用每个索引实例的编号填充
indexArrayFIX[]
。例如,有2个“9”,因此在
indexArrayFIX[]
的索引9处,我想显示一个2:

indexArrayFIX[]
应输出:

2 2 0 0 0 1 1 2 1 0 0 0 0 0 2 1 1 0

希望这有意义

谢谢

为什么不呢

for (int i = 0; i < indexArrayHIS.length; i++) {
    indexArrayFIX[indexArrayHIS[i]]++;
}
for(int i=0;i
为什么不呢

for (int i = 0; i < indexArrayHIS.length; i++) {
    indexArrayFIX[indexArrayHIS[i]]++;
}
for(int i=0;i
谢谢,这似乎是正确的。由于数组的长度不同,我使用了两个for循环,得到了:40 40 0 0 0 20 20 20 0 0 0 0 0 0 40 20 20 0 0 0 0 20 0 0 0 0 0 0 0 0 20 0 0 0 0次,似乎在正确的轨道上。由于数组的长度不同,我使用了两个for循环,得到了:40 40 0 0 0 20 20 20 0 0 0 0 0 40 20 0 0