public class MyClass {
public static String AddLeadingZerosToNegativeNumber(int num, int digits) {
boolean negative = false;
if (num < 0) {
num *= -1;
negative = true;
}
String s = Integer.toString(num);
while (s.length() < digits) {
s = "0" + s;
}
if (negative) {
return "-" + s;
}
return s;
}
public static void main(String args[]) {
int num = -5;
System.out.println(AddLeadingZerosToNegativeNumber(num, 3));
}
}
/*
run:
-005
*/