Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String int2String(int n) {
- if (n == 0) {
- return "0";
- }
- List<String> digits = new ArrayList<>();
- boolean isNegative = n < 0;
- if (isNegative) {
- n = n * -1;
- }
- while (n > 0) {
- int digit = n % 10;
- digits.add(digit2String(digit));
- n = n / 10;
- }
- String result = "";
- for (int i = digits.size() - 1; i >= 0; i--) {
- result += digits.get(i);
- }
- if (isNegative) {
- result = "-" + result;
- }
- return result;
- }
- public static String digit2String(int digit) {
- // Chosen implementation here...
- }
Add Comment
Please, Sign In to add comment