Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public static String int2String(int n) {
  2. if (n == 0) {
  3. return "0";
  4. }
  5.  
  6. List<String> digits = new ArrayList<>();
  7. boolean isNegative = n < 0;
  8. if (isNegative) {
  9. n = n * -1;
  10. }
  11.  
  12. while (n > 0) {
  13. int digit = n % 10;
  14. digits.add(digit2String(digit));
  15. n = n / 10;
  16. }
  17.  
  18. String result = "";
  19. for (int i = digits.size() - 1; i >= 0; i--) {
  20. result += digits.get(i);
  21. }
  22. if (isNegative) {
  23. result = "-" + result;
  24. }
  25.  
  26. return result;
  27. }
  28.  
  29. public static String digit2String(int digit) {
  30. // Chosen implementation here...
  31. }
Add Comment
Please, Sign In to add comment