Wednesday, February 25, 2009

Puzzle 1 - Solution

The key to solving this puzzle is ' Ascii Characters have a numeric equivalent.'

Solution 1 - A simple approach is to print the Ascii Value of 'W' directly.
package com.twisters;
public class Hello {
public static void main(String args[]){
System.out.println("Hello "+(char)87+"orld");
}
}
Solution 2 - You can make use of the overloaded '+' operator to perform character additions.
package com.twisters;
public class Hello {
public static void main(String args[]){
char letter = 'V' + 1;
System.out.println("Hello "+letter+"orld");
}
}
Solution 3 - A cheeky solution is to use double 'U' to form a 'W'
package com.twisters;
public class Hello {
public static void main(String args[]){
System.out.println("Hello UUorld");
}
}
Congrats to
1. COMMANDER RV
for getting the right answer.

I'll be putting up a score board soon. Stay tuned for the next puzzle...

1 comment:

  1. System.out.println("Hello "+"\u0077"+"orld");

    put the statement in main method

    nsureshreddy@live.com

    ReplyDelete

Solution for this question?