public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = { 10, 20, 30, 10, 30, 10, 30, 40, 50 };
System.out.println(“enter the number”);
Scanner scn = new Scanner(System.in);
int data = scn.nextInt();
int i = 0;
int counter = 0;
while (i < a.length) {
if (a[i] == data)
{
counter = counter + 1;
}
i++;
// first i found out the array length
}
System.out.println(counter);
int[] array = null;// declared new array
array = new int[counter];
while(i<a.length) {
if(a[i]==data) {
for(int j =0;j<counter;j++) {
array[j] = i;
}
}
i++;
}
for( i=0;i<counter;i++) {
System.out.println(array[i]);
}
}
}