We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec862d2 commit fb973f5Copy full SHA for fb973f5
Pepcoding/FunctionsAndArrays/CountDigit.java
@@ -0,0 +1,23 @@
1
+package FunctionsAndArrays;
2
+
3
+public class CountDigit {
4
5
+ public static int countDigit(int num, int digit) {
6
+ if (num < 0)
7
+ num = -num;
8
9
+ int count = 0;
10
+ while (num != 0) {
11
+ int rem = num % 10;
12
+ if (rem == digit)
13
+ count++;
14
+ num /= 10;
15
+ }
16
+ return count;
17
18
19
+ public static void main(String[] args) {
20
+ System.out.println(countDigit(956545235, 5));
21
+ System.out.println(countDigit(-956545235, 5));
22
23
+}
0 commit comments