This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding SCJP1.5 (foramt and printf)

 
Suguna Gollapally
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the + before your (x, y, sum) variables.... it should be a ,

this runs fine (no MissingFormatArgumentException)....

 
Suguna Gollapally
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tnx Bod..Simple mistake
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic