Thursday, January 27, 2005

What is the output ?

Look at the following piece of code and figure out what would be the output. There is something very tricky about this code, which does not allow it to work as you would expect it to.
I recently came across such a nasty bug in our code at work, and spent about two hours looking all around the codebase before finding the flaw. Silly me !!

public class Tricky {

  public static void main(String[] args

  {

    for (int i = 0; i < 10; i++) {

      if(i % == 1);

      {

        System.out.println("Hello World #" + i);

      }  

    }

  }

}

1 Comments:

Blogger Chirag said...

cool man! you found it ! Yeah man you were always good and finding and creating such silly bugs ever since our FSS days.
Keep it up man !

June 12, 2005 at 9:26 PM  

Post a Comment

<< Home