-
-
Save benjholla/e0c5b47bab64f015095740d48366bb5f to your computer and use it in GitHub Desktop.
Java Puzzle 21 (What does this program output?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayOutputStream; | |
import java.io.PrintStream; | |
public class Puzzle21 { | |
public static void main(String[] args) { | |
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | |
PrintStream oldStream = System.out; | |
PrintStream newStream = new PrintStream(bytes); | |
System.setOut(newStream); | |
System.setErr(newStream); | |
System.out.print(0 + "_" + 0); | |
System.out.print(0_0); | |
System.out.print(0_0_0); | |
System.out.print(0_0_0L); | |
System.out.print(0_0_0.0F); | |
String string = new String(bytes.toByteArray()); | |
System.setOut(oldStream); | |
try { | |
System.out.println(Double.parseDouble(string)); | |
} catch (Throwable t) { | |
t.printStackTrace(); | |
} | |
System.out.println("Cool."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment