Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes simple print statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple print statement" Watch "simple print statement" New topic

simple print statement

Kailash Bisht

Joined: Sep 03, 2012
Posts: 5

Which code fragment, inserted at line 4, produces the output | 12.345|?
A. System.out.printf("|%7d| \n", d);
B. System.out.printf("|%7f| \n", d);
C. System.out.printf("|%3.7d| \n", d);
D. System.out.printf("|%3.7f| \n", d);
E. System.out.printf("|%7.3d| \n", d);
F. System.out.printf("|%7.3f| \n", d);

can anyone explain me how does this code works..??
Anayonkar Shivalkar

Joined: Dec 08, 2010
Posts: 1502

Hello Kailash Bisht,

Welcome to CodeRanch!

Plese, UseCodeTags. As of now, I've edited your post and added code tags. It makes much easier for others to read the code.

Secondly, please SearchFirst. Did you tried by inserting all those given lines? Did you see what kind of outputs are produced by those?

Once you've done that, and if you still have doubt(s) about any specific option, please feel free to ask.

I hope this helps.

Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37950
And you should always tell us where such questions come from. I presume you know all about the % tags: if not, start here and use ctrl‑F‑formatting to find the appropriate sections (I think there are two).
wood burning stoves
subject: simple print statement
Similar Threads
Array Vs VarArgs
Displaying the largest and smallest of three integers
Is final variables are override
printf() :: :banghead: Strange Output on one Arcitecture
format query