Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding SCJP1.5 (foramt and printf)

 
Suguna Gollapally
Ranch Hand
Posts: 37
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tnx Bod..Simple mistake
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic