am new to programming and im trying Java, i created this array and gives me this error, task is to count all positive and negative no and place it in new array i called pArr and nArr, and after that to count duplicates and write them and how many times they repeat, can someone help me?
public static void main(String[] args) {
int[] array = {12, 23, -22, 0, 43, 545, -4, -55, 43, 12, 0, -999, -87};
int brPoz=0, brNeg=0;
for(int a=0; a<array.length; a++){
if(array[a]>0)
brPoz++;
else if (array[a]<0)
brNeg++;
}
int[] pArr = new int[brPoz];
int[] nArr = new int[brNeg];
for (int i = 0; i < array.length; i++) {
if (array[i] > 0) {
pArr[i] = array[i];
}
}
for (int i = 0; i < array.length; i++) {
if (array[i] < 0) {
nArr[i] = array[i];
}
}
Arrays.sort(array);
Arrays.sort(pArr);
Arrays.sort(nArr);
System.out.println(java.util.Arrays.toString(array));
System.out.println(java.util.Arrays.toString(pArr));
System.out.println(java.util.Arrays.toString(nArr));
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length; j++) {
if ((array[j])==array[i]) {
System.out.println("Duplikati su: "+array[j]);
}
}
}