File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding SCJP1.5 (foramt and printf) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding SCJP1.5 (foramt and printf)" Watch "Regarding SCJP1.5 (foramt and printf)" New topic

Regarding SCJP1.5 (foramt and printf)

Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37

I am preparing for SCJP1.5 exam..Can anyone tell me the output of following programs

class Test {

public static void main(String arg[]) {

int x=5;
int y=6;
int sum=x+y;

System.out.printf("%d + %d = %d\n"+x,y,sum);
System.out.format("%d + %d = %d\n"+x,y,sum);

System.out.println(x + "+" + y + "= " + sum);

why am i getting run time exception for first 2 sop statements? I tried with %1$d %2$d also
Bod Toki
Ranch Hand

Joined: Sep 01, 2006
Posts: 95
check the + before your (x, y, sum) variables.... it should be a ,

this runs fine (no MissingFormatArgumentException)....

Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37
Tnx Bod..Simple mistake
I agree. Here's the link:
subject: Regarding SCJP1.5 (foramt and printf)
It's not a secret anymore!