So I need to print out the table of conversions from kilogram to pound and from pounds to kilograms. I think I have done a while loop correctly, but it is hard to actually check it since I do not have proper output format.
I have tried also %4.2f format option however could not find the proper position in the print.
Can somebody assist me please.
it needs to be something like: System.out.printf ("%.2f", pounds);
so , its pounds, not "pounds" . you are using string value as the second argument
Edited.
You certainly don't want to be using %s because that is for formatting strings, so why don't you show us the code that is using %f formatting and also tell us exactly what is wrong with the output
i.e. what output were you expecting and what output did you get ?
Joanne Neal wrote:You certainly don't want to be using %s because that is for formatting strings, so why don't you show us the code that is using %f formatting and also tell us exactly what is wrong with the output
i.e. what output were you expecting and what output did you get ?
Lovro Bajc wrote:
here is the picture how it should look like:
And my current printout looks like this:
i think this works. remember , %f stands for double and float, %d for integer type, and %s which is not used here, is for string, you can use a type cast as needed.
what i'v done is counting the white space in the first line and set the numbers in format identifers
Ngml Bishop wrote: . . . %f stands for double and float, %d for integer type, and %s which is not used here, is for string, . . .
No %f stands for fixed‑point, and %d stands for decimal integer.
If you go through the Formatter documentation you find you can only use %f with numbers which might need a decimal point (double float and BigDecimal) and %d only with integers. You should read that documentation (even if you immediately forget 99.9% of it) and the two Java Tutorials sections about formatting: try here: No 1 and No 2.