In this example,we will see how to format and display country’s zip code in Java.
Source Code
1) ZipCode – int
package com.beginner.examples;
import java.text.DecimalFormat;
public class ZipCodeExample1 {
public static void main(String[] args) {
int zipCode = 43;
DecimalFormat format = new DecimalFormat("00000");
System.out.println(format.format(zipCode));
}
}
Output:
00043
2) ZipCode – String
package com.beginner.examples;
public class ZipCodeExample2 {
public static void main(String[] args) {
String zipCode = "00043";
System.out.println(zipCode);
}
}
Output:
00043
References
Imported packages in Java documentation: