Re: printing the "%" charcter
Roy Gourgi wrote:
Hi,
I am trying to print out the "%" character but I get an error.
This is my statement:
System.out.printf("Odds same percentage Move " + sInteger15 + "%" + "\n",
iDirectionOdds);
I am trying to print out the number followed by the percentage (%) sign.
Example: 15%
How would I do it.
TIA
Roy
The reason you are getting the error is because you are using the
PrintStream.printf() method which prints formatted strings and % is a special
character in the format specifier. Read the documentation at
http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html
to see how to format a string.
Your argument list seems to be a little confused. Which variable are you trying
to have printed, sInteger15 or iDirectionOdds, or both? If you only want
sInteger15 followed by a percent use PrintStream.print() and drop the
unnecessary iDirectionOdds from the argument list. Better still use println()
and drop the "\n".
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555