0
How can I count how many of a digit is in an array?
5 Answers
+ 3
int[] numbers = new int[10];
System.out.println(numbers.length);
//output
10
+ 3
Mimi
Is the array type numeric (int) or string? if it was string array, you can use `String.contains` method to verify whether a string (the number) contains another string (digit/number you want to search). But that method only checks for existence, it doesn't count number of occurrence.
If it was an int array then you can use modulo operator to check for a digit in each array element. Mind that you may need to calculate the divisor in case the number you seek for is more than one digit.
+ 2
array.Lenght?
0
D'Lite _yaroslavv [online_everyday]
No, I mean if I have an array like:
int[] arr = {10,4,8,43,4};
And I want to know how many 4's are in the array (3).
How do I do this?
0
In other words: is there a method like:
str.has(digit);
Or something?