In JAVA I declared an int variable and need to print it. my code:
public int i=0;
System.out.println(i);
Output:1 but I my required output is 01 How can I do this?
Thanks in advance
Do this :
<%
int var=1;
out.println(var<10 ? "0"+var : var);
%>
Or, more typically, isolating a little the algorithm from the presentation :
<%
int var=1;
%>
<%= var<10 ? "0"+var : var %>
If you want to do more complex number formating, have a look at DecimaFormat.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With