Link

Puzzle (Classy Fire)

Consider the following example.

package demo;

public class App {
  public static void main( String[] args ) {
    System.out.println( classify( 'n' ) + classify( '+' ) + classify( '2' ) );
  }

  static String classify( char ch ) {
    if ( "0123456789".indexOf( ch ) >= 0 )
      return "NUMERAL ";

    if ( "abcdefghijklmnopqrstuvwxyz".indexOf( ch ) >= 0 )
      return "LETTER ";

    /* (Operators not supported yet)
        if ("+-*/&|!=".indexOf(ch) >= 0)
    return "OPERATOR ";
    */

    return "UNKNOWN ";
  }
}

What do you think the program will print?

This example was taken from PUZZLE 19: CLASSY FIRE in Java™ Puzzlers: Traps, Pitfalls, and Corner Cases.

As you can see, the comment ends inside the string, which quite naturally contains the characters */. The resulting program is syntactically invalid. Our attempt to comment out a section of the program failed because string literals are not treated specially within comments.