This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Regarding SCJP1.5 (foramt and printf)
 
It's not a secret anymore!