Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2018 15:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Java Puzzle 5 (spot the bug if one exists)
import java.util.Random;
public class Puzzle5 {
private static Random rnd = new Random();
public static void main(String[] args) {
StringBuffer word = null;
switch(rnd.nextInt(2)) {
case 1: word = new StringBuffer('R');
case 2: word = new StringBuffer('T');
default: word = new StringBuffer('J');
System.out.println(String.format("It's time for a %s.", word));
Copy link

Adapted from Java Puzzlers: Traps, Pitfalls, and Corner Cases - Puzzle #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment