Basically the aim of this problem is to count the number of times the number 9 is typed in the array, for example, arrayCountNines([1, 9, 9, 3, 9]) = 3
I have tried doing a Stream of the numbers, for example by using .collect but that didn't seem to work. Also tried HashMaps
public class NewClass4 {
public int arrayCountNines(int[] nums) {
HashMap < Character, Integer > map = new HashMap<>();
for (int i =0; i<nums.length; i++) {
char[] charr = String.valueOf(nums[i]).toCharArray();
for(int j = 0; j<charr.length; j++) {
if(map.containsKey(charr[j])) {
map.put(charr[j], map.get(charr[j])+1);
}
else {
map.put(charr[j], 1);
}
}
}
return 1;
}
}
]1
It doesn't return the number of times 9 is in the array