Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java Puzzle 21 (What does this program output?)
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