• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A tough one - on flow control

 
Shailendra Guggali
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try the foll code :
class TeastClass
{
public static void main(String args[ ] )
{
int k = 0; int m = 0;
for ( int i = 0; i <= 3; i++)
{
k++;
if ( i == 2)
{
// line 1
}
m++;
}
System.out.println( k + ", " + m );
}
}
// which statements are correct when inserted at line //1
// 1. break; will print 3,2
// 2. continue; will print 4,3
// 3. i = 4; will print 3,3
// 4. continue; will print 3,2
// 5. i = m++; will print 4,4
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it is tough. basically u have to plug and play each option. Options 1,2,3 are correct.
option 5 is little bit catchy. but it will print 4,5 not 4,4. thats the only thing u need to be careful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic