When I tried to use Date argument while formatting, I could see a runtime exception which is not expected.
import java.util.*;
public class Format {
public static void main(String[] arg) {
Formatter formatter = new Formatter(System.out);
System.out.println(" Welcome to formatting world.. ");
int ni = 2902;
formatter.format("%0$-80s Is the argument \n",arg);
formatter.format("%0$80s Is the argument \n",arg);
formatter.format("%0$^80s Is the argument \n",arg);
formatter.format("%mt is month ",new Date());
}
}
console output.
vishalb:/home/vv145429/tiger/src/formating 65 % java Format Sun Microsystems
Welcome to formatting world..
Sun Is the argument
Sun Is the argument
SUN Is the argument
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'm'
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2370)
at java.util.Formatter.parse(Formatter.java:2212)
at java.util.Formatter.format(Formatter.java:2146)
at java.util.Formatter.format(Formatter.java:2100)
at Format.main(Format.java:11)
import java.util.*;
public class Format {
public static void main(String[] arg) {
Formatter formatter = new Formatter(System.out);
System.out.println(" Welcome to formatting world.. ");
int ni = 2902;
formatter.format("%0$-80s Is the argument \n",arg);
formatter.format("%0$80s Is the argument \n",arg);
formatter.format("%0$^80s Is the argument \n",arg);
formatter.format("%mt is month ",new Date());
}
}
console output.
vishalb:/home/vv145429/tiger/src/formating 65 % java Format Sun Microsystems
Welcome to formatting world..
Sun Is the argument
Sun Is the argument
SUN Is the argument
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'm'
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2370)
at java.util.Formatter.parse(Formatter.java:2212)
at java.util.Formatter.format(Formatter.java:2146)
at java.util.Formatter.format(Formatter.java:2100)
at Format.main(Format.java:11)