VOOZH about

URL: https://www.geeksforgeeks.org/java/few-tricky-programs-in-java/

⇱ Few Tricky Programs in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Few Tricky Programs in Java

Last Updated : 25 Sep, 2017
  1. Comments that execute : Till now, we were always taught "Comments do not Execute". Let us see today "The comments that execute" Following is the code snippet: Output:
    comment executed
    The reason for this is that the Java compiler parses the unicode character \u000d as a new line and gets transformed into:
  2. Named loops :
Output:
i = 0 j = 0
i = 0 j = 1
i = 0 j = 2
i = 0 j = 3
i = 0 j = 4
i = 1 j = 0
i = 1 j = 1
i = 1 j = 2
i = 1 j = 3
i = 1 j = 4
i = 2 j = 0
i = 2 j = 1
i = 2 j = 2
i = 2 j = 3
i = 2 j = 4
You can also use continue to jump to start of the named loop. We can also use break (or continue) in a nested if-else with for loops in order to break several loops with if-else, so one can avoid setting lot of flags and testing them in the if-else in order to continue or not in this nested level.
Comment
Article Tags: