KCE / Java

Java Programming Language
0 stars 3 forks source link

CoreTask#3: CountDigits - Submit Your Code in Comment Section #28

Open ErSKS opened 5 years ago

ErSKS commented 5 years ago

CoreTask#3: CountDigits - Write a function named countDigit that returns the number of times that a given digit appears in a positive number. For example countDigit(32121, 1) would return 2 because there are two 1s in 32121. Other examples: countDigit(33331, 3) returns 4 countDigit(33331, 6) returns 0 countDigit(3, 3) returns 1 The function should return -1 if either argument is negative, so countDigit(-543, 3) returns -1. The function signature is int ountDigit(int n, int digit) Hint: Use modulo base 10 and integer arithmetic to isolate the digits of the number.

Niranjan2054 commented 5 years ago

package countdigit;

/**