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

Jersey Making Moxy work with Jackson
How to get informations of request on ExceptionMapper of Jersey
Google map compass error with 0.67dp view
explaining this simple program - bucket sort
converting my files to blob then inserting to database
Creating a count down timer- Java
How to prevent progurad from keeping singleton classes names
What is the proper way to use scanner to store user input with an array? [duplicate]
How can i use args.length control in android
Rollover on JLabel which consists of image within grid layout?
How do I use mouseListener to add a new Image in Slick2d
NameAlreadyBoundException using JNDI
Serving files using Spring-Boot and Spring-MVC from any location in the file system
Can't get the spring-ws apache camel example to work
How to set path in fileinputstream using jasper report, image uploading?
Glassfish server log flodding with Interrupting idle Thread

Categories

HOME
vim
log4j
proxy
netbeans
magnific-popup
iterator
bpmn
sql-server-2016
baqend
opengl-es-2.0
mouse
google-translate
kibana-4
circular-dependency
windows-server-2012
finite-automata
serilog
interop
plunker
scriptcs
wijmo
sqlcipher
su
chromebook
bootstrap-duallistbox
greendao
web-api-testing
fifo
ping
vision
tinymce-4
scorm2004
lxd
environment-modules
wixsharp
x11-forwarding
event-driven
hue
tasker
gzipstream
http-live-streaming
fakeiteasy
import-from-excel
strptime
upstart
datastax-startup
dropbox-php
aurelia-validation
statsd
libusb-win32
r-forge
linode
orthogonal
crosswalk-runtime
pycaffe
angular-strap
pcf
ctest
simplewebrtc
bluegiga
cloudbees
xna-4.0
jms2
wyam
responsive-images
php-ci
nsight
fscommand
clicktag
gui-test-framework
relocation
id3v2
internet-connection
article
heisenbug
jboss-weld
resty-gwt
algebraic-data-types
web2py-modules
quartz-graphics
opcache
tinn-r
nsnetservice
labwindows
netdna-api
whoosh
gwt-ext
celltable
infrastructure
mirah
database-management
multi-tier
ti-dsp
boost-smart-ptr
premature-optimization
sector
mediarss
geneva-server

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App