Say that I have to add two integers one being 0001 and the other 0002. If I add it in java then I get 3 however I would like 0003. Would I have to make a loop to map out the zeros or is there an easier way.
解决方案
Don't confuse numbers with String representation of numbers. Your question revolves around the latter -- how to represent a number as a String with leading zeros, and there are several possible solutions including using a DecimalFormat object or String.format(...).
i.e.,
int myInt = 5;
String myStringRepOfInt = String.format("%05d", myInt);
System.out.println("Using String.format: " + myStringRepOfInt);
DecimalFormat decimalFormat = new DecimalFormat("00000");
System.out.println("Using DecimalFormat: " + decimalFormat.format(myInt));