MCPcopy Create free account
hub / github.com/careercup/ctci / numberOf2s

Method numberOf2s

java/Chapter 18/Question18_4/QuestionBrute.java:5–14  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

3public class QuestionBrute {
4
5 public static int numberOf2s(int n) {
6 int count = 0;
7 while (n > 0) {
8 if (n % 10 == 2) {
9 count++;
10 }
11 n = n / 10;
12 }
13 return count;
14 }
15
16 public static int numberOf2sInRange(int n) {
17 int count = 0;

Callers 1

numberOf2sInRangeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected