File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple print statement" Watch "simple print statement" New topic
Author

simple print statement

Kailash Bisht
Greenhorn

Joined: Sep 03, 2012
Posts: 5
Given:

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
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

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.


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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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).
 
 
subject: simple print statement
 
Similar Threads
printf() :: :banghead: Strange Output on one Arcitecture
Array Vs VarArgs
format query
Is final variables are override
Displaying the largest and smallest of three integers