java


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());

Related Links

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

Categories

HOME
cookies
gremlin
dictionary
nullpointerexception
office365api
session
platform-builder
rsyslog
adb
sqlite-net-extensions
dxl
datastax-java-driver
spring-kafka
row
quicklook
spring-tool-suite
flask-wtforms
iolanguage
libtiff
seaborn
jsdoc
http-status-code-504
django-cms
lucene.net
java-3d
scriptcs
orleans
realex-payments-api
fish
semantic-analysis
brunch
facebook-apps
windows-server-2000
procdump
nouislider
stormpath
android-kernel
gammu
jmonkeyengine
suricata
hockeyapp
objectlistview
optix
keydown
executenonquery
flickr-api
parentheses
termination
react-scripts
ionicons
svmlight
jxcore
sqlclient
media-player
mcafee
messenger
ado.net-entity-data-model
ctest
plottable.js
captivenetwork
dataview
reactive-banana
metaclass
libressl
iis-arr
dukescript
kineticjs
nstableviewcell
codeigniter-routing
system.net.webexception
mechanize-ruby
datagridviewcolumn
java.nio.file
centos5
odata4j
eclipse-memory-analyzer
django-nonrel
frameset
javaspaces
tridion-worldserver
appconkit
asyncfileupload
php-parser
zpt
genshi
jmock
xfbml
cxxtest
digest-authentication
paster
routedevent
swing-app-framework
eqatec
pascal-fc
nerddinner
zend-decorators
scripting-languages
mdac
geneva-server
grid-system
ntvdm.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App