This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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: 1541

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: 44048
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).
Have you checked out Aspose?
subject: simple print statement
It's not a secret anymore!