Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

JAVA CODE . Will give medal I'm writing a code that asks for user input in the main class and in a tester class I need to call on that user input and display a statement regarding the input with it formatted to only 2 decimal points, so I'd use System.out.printf("% and usually say if the number was 5.25 i'd put System.out.printf("%4.2f"); but since java is accomodating when using printf and doesn't cut off part of the number to the left of the decimal, it doesn't matter if i put "%6.2f" or "%1.2f" right? or is that not true?

OpenStudy (anonymous):

meaning if my user enters something like 1670.78932 and my code reads System.out.printf("%2.2f"); it would still print as "1670.78" right?

OpenStudy (anonymous):

I believe so.

OpenStudy (anonymous):

Hey @V1r3z do you know Java? I'd love to run a few things by you and see your opinion if you do

OpenStudy (anonymous):

Yes I'm pretty knowledgeable with Java.

OpenStudy (woodrow73):

Mhm, if the width is less than the number, the width will default to the number's size. You can see more on the format here: http://openstudy.com/users/woodrow73#/updates/56e04d06e4b0de40e34f1c5d https://www.cs.colostate.edu/~cs160/.Spring16/resources/Java_printf_method_quick_reference.pdf

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!