Java program to
automate keyboard key press and mouse click events
public class Test2 { public static void main(String[] args) { String value1="123"; int defaultLength=8; String leftPadZero=leftPaddingWithZeroVal(value1, defaultLength); System.out.println(leftPadZero); } private static String leftPaddingWithZeroVal(String value, int defaultLength) { String formattedValue=""; try { int num = Integer.parseInt(value); formattedValue = String.format("%0" + defaultLength + "d", num); System.out.println(formattedValue); }catch (Exception e) { e.printStackTrace(); } return formattedValue; } }
Output of the Above Programs
00000123