Write a program for a String must contain three digit using String.format()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.javasunderesan;
public class StringThreeDigit {
public static void main(String[] args) {
try
{
int no = 0;
String formattingString = null;
for (int i = 0; i < 10; i++) {
formattingString = String.format("Dev - %03d", no);
System.out.println(formattingString);
no++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
|
OutputDev - 000 Dev - 001 Dev - 002 Dev - 003 Dev - 004 Dev - 005 Dev - 006 Dev - 007 Dev - 008 Dev - 009
No comments :
Post a Comment