(int n)
| 3 | public 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; |