File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 11package com .thealgorithms .maths ;
22
3+ /**
4+ * A positive integer is considered uniform if all
5+ * of its digits are equal. For example, 222 is uniform,
6+ * while 223 is not.
7+ * Given two positive integers a and b, determine the
8+ * number of uniform integers between a and b.
9+ */
310public final class UniformNumbers {
4-
511 // Private constructor to prevent instantiation of the utility class
612 private UniformNumbers () {
713 // Prevent instantiation
814 }
9-
15+ /**
16+ * This function will find the number of uniform numbers
17+ * from 1 to num
18+ * @param num upper limit to find the uniform numbers
19+ * @return the count of uniform numbers between 1 and num
20+ */
1021 public static int uniformNumbers (int num ) {
1122 String numStr = Integer .toString (num );
1223 int uniformCount = (numStr .length () - 1 ) * 9 ;
@@ -20,7 +31,13 @@ public static int uniformNumbers(int num) {
2031
2132 return uniformCount ;
2233 }
23-
34+ /**
35+ * This function will calculate the number of uniform numbers
36+ * between a and b
37+ * @param a lower bound of range
38+ * @param b upper bound of range
39+ * @return the count of uniform numbers between a and b
40+ */
2441 public static int countUniformIntegers (int a , int b ) {
2542 if (b > a && b > 0 && a > 0 ) {
2643 return uniformNumbers (b ) - uniformNumbers (a - 1 );
You can’t perform that action at this time.
0 commit comments