Integer Convert Into String
Integer Convert into String
public class convertIntToStringWitInBuMeth {
public static String intToString(int n) {
String result = "";
boolean isNegative = false;
if (n < 0) {
isNegative = true;
n = -n; // convert negative value into positive
}
if (n == 0) {
result = "0";
} else {
while (n > 0) {
int digit = n % 10;
char digitChar = (char) (digit + '0');
result = digitChar + result;
n /= 10;
}
}
if (isNegative) {
result = '-' + result;
}
return result;
}
public static void main(String[] args) {
int n = 12;
String s = intToString(n);
System.out.println(s);
}
}
Comments
Post a Comment