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

Method numToString

java/Chapter 17/Question17_7/Question.java:11–31  ·  view source on GitHub ↗
(int number)

Source from the content-addressed store, hash-verified

9 public static String[] bigs = {"", "Thousand", "Million", "Billion"};
10
11 public static String numToString(int number) {
12 if (number == 0) {
13 return "Zero";
14 }
15
16 if (number < 0) {
17 return "Negative " + numToString(-1 * number);
18 }
19 int count = 0;
20 String str = "";
21
22 while (number > 0) {
23 if (number % 1000 != 0) {
24 str = numToString100(number % 1000) + bigs[count] + " " + str;
25 }
26 number /= 1000;
27 count++;
28 }
29
30 return str;
31 }
32
33 public static String numToString100(int number) {
34 String str = "";

Callers 1

mainMethod · 0.95

Calls 1

numToString100Method · 0.95

Tested by

no test coverage detected