hello,
i wrote a code to encrypt the 4 digit number.
i broke the number in digits and encrypted it.
It works fine. But the problem comes when first digit in output comes 0.
that time i get 3 digit number instead of 4 digit number. i want it to show 0(3 digit answer).
how can i fix the length of the output number to 4 ?

Use DecimalFormat

DecimalFormat df = new DecimalFormat("0000");
      int a=23;
      System.out.println(df.format(a));

i found it out as
%04d\n in printf statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.