permaculture playing cards*
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 Android Security Essentials Live Lessons this week in the Android 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
Author

Regarding SCJP1.5 (foramt and printf)

Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37
Hi,

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
 
Consider Paul's rocket mass heater.
 
subject: Regarding SCJP1.5 (foramt and printf)
 
Similar Threads
SCJP1.5
SCJP1.5
scjp1.5
Scjp1.5
Need explanations of inheritance