| Author |
printing the "%" charcter
|
|
| Roy Gourgi 2007-06-21, 10:08 pm |
| 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
| |
| Flo 'Irian' Schaetz 2007-06-21, 10:08 pm |
| And thus spoke Roy Gourgi...
> System.out.printf("Odds same percentage Move " + sInteger15 + "%" + "\n",
> iDirectionOdds);
Use %%.
Flo
| |
| Jeff Higgins 2007-06-21, 10:08 pm |
|
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);
Exception in thread "main" java.util.UnknownFormatConversionException:
Conversion = '%'
>
> I am trying to print out the number followed by the percentage (%) sign.
>
> Example: 15%
>
> How would I do it.
public class PrintPercentage
{
public static void main(String[] args)
{
int percent = 15;
System.out.print(percent + "%");
}
}
>
> TIA
>
> Roy
>
| |
| Nigel Wade 2007-06-21, 10:08 pm |
| 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/a...rintStream.html
to see how to format a string.
Your argument list seems to be a little . 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
| |
| Bluto Blutarsky 2007-06-21, 10:08 pm |
| 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
>
>
....i know shit but i'd try escaping it
System.out.printf("Odds same percentage Move " + sInteger15 + \% + "\n",
.... maybe
b
--
Sometimes I'm in a good mood.
Sometimes I'm in a bad mood.
When all my moods have cum to pass
i hope they bury me upside down
so the world can kiss me porcelain,
white, Irish bottom.
| |
|
| Roy Gourgi wrote:
A question is indicated typographically by a question mark ('?') at the end of
a sentence.
Bluto Blutarsky wrote:[color=darkred]
> ...i know shit but i'd try escaping it
> System.out.printf("Odds same percentage Move " + sInteger15 + \% + "\n",
> ... maybe
And you would find that it didn't work.
Why speak from ignorance when you can look up
<http://java.sun.com/javase/6/docs/a...ter.html#syntax>
and know without doubt?
Or you could read the correct answer that was provided upthread.
--
Lew
| |
|
|
|
|
|
|
|
|
|
|