System.out.printf method throws a flags exception
I'm reading a documentation for the Formatter.format and System.out.printf methods (Java 6) and I'm trying to practice what I learned. I'm facing to an exception that seems to me unjustified, or there is a problem of understanding the topic. The code I wrote is simple: final int i = -15; System.out.printf("%1$-+06d", i); What I expect is having an int printed with the following format 1) pad to left ; - 2) view the sign (négatif or positif); + 3) complete with left zeros; 0 4) print on 6 columns (characters); 6 Instead, an exception is thrown and I don't know why: Exception in thread "main" java.util.IllegalFormatFlagsException: Flags = '-+0' at java.util.Formatter$FormatSpecifier.checkNumeric(Formatter.java:2935) at java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:2890) at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2643) at java.util.Formatter.parse(Formatter.java:2480) at java.util.Formatter.format(Formatter.java:2414) at java.io.PrintStream.format(PrintStream.java:920) at java.io.PrintStream.printf(PrintStream.java:821) at cert.simo.formats.Test.main(Test.java:18) Any Explainations? Thank you.
"-" and "0" are incompatible options. You either pad with zeros or align to the left. Down below is part of java 6 source code (v6-b14) causing this exception. if ((f.contains(Flags.PLUS) && f.contains(Flags.LEADING_SPACE)) || (f.contains(Flags.LEFT_JUSTIFY) && f.contains(Flags.ZERO_PAD))) throw new IllegalFormatFlagsException(f.toString());
How to deal with abstract classes and implementations in Eclipse
Google maps api v2 show all markers tittle always without any click
add cxf jar file in maven project?
How to converting TIFF image file to Bitmap Android
How do I get a Text Area in Netbeans to display content that I already have saved in a Text File?
Persisting an Entity in derby DB Using EntityManager gives java.sql.SQLIntegrityConstraintViolationException
Route created using java DSL does not give any clue if the routes were executed properly. Using apache AHC compoenet also as one of the component
Run Java program on Windows Command Line 1000 times
Make a transformed copy of a List using ArrayList constructor [duplicate]
Shared Preferences not working with Contacts in ListView
Interrupting threads in java
System environment variables in Jetty application
perceptron algorithm calculation of local error / RMSE
Why modification in file shows Access Denied?
How to index an array of element in Elasticsearch?
SWT Nebula gantt chart component