Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deal with loops.....

 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the easiest way to get the answer for the following code??? Since we�ll be short of time , how is it best to work out this problem and find the result values? write on paper or???
class Testjranch
{
public static void main(String args[ ] )
{
int k = 0;
int m = 0;
for ( int i = 0; i <= 3; i++)
{
k++;
System.out.println( k + " k after k++, " + m );
if ( i == 2)
{
continue;
}
m++;
System.out.println( k + " m after m++," + m );
}
System.out.println( k + " outside for loop, " + m );
}
}
 
Bhuvana Dhruva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i think the best way is to work it out on paper. i don't think that u will lose much time in that and also can reduce errors, things will be more clear.
bhuvana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic