one question about printf()

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
icepeanuts
Posts: 53
Joined: Thu Nov 22, 2012 12:01 am
Contact:

one question about printf()

Post by icepeanuts »

I tried the code below. The result is "hell". But I do not understand why. Could anyone help me out? Thanks.

System.out.printf("%3.4s\n", "hello world");

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: one question about printf()

Post by admin »

It is quite straight forward. Please go through this: http://web.cerritos.edu/jwilson/SitePag ... erence.pdf
Please check how width and precision work for strings.

icepeanuts
Posts: 53
Joined: Thu Nov 22, 2012 12:01 am
Contact:

Re: one question about printf()

Post by icepeanuts »

this is very helpful, thank u.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests