This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String toString(int n) { | |
String sign = ""; | |
String num = ""; | |
if (n == 0) { | |
return "0"; | |
} else if (n < 0) { | |
sign = "-"; | |
n = -n; | |
} | |
while (n != 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String format(int n) { | |
String num = "" + n; | |
String stringNum = ""; | |
int numLength = num.length(); | |
for (int i = 0; i < numLength; i++) { | |
if ((numLength - i) % 3 == 0 && i != 0) { | |
stringNum += ","; | |
} | |
stringNum += num.charAt(i); | |
} |
NewerOlder