Skip to content

Instantly share code, notes, and snippets.

@benjholla
Created September 10, 2018 15:03
Show Gist options
  • Save benjholla/e83bc9c8354e47a47a83757ac905903d to your computer and use it in GitHub Desktop.
Save benjholla/e83bc9c8354e47a47a83757ac905903d to your computer and use it in GitHub Desktop.
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');
}
word.append("est");
System.out.println(String.format("It's time for a %s.", word));
}
}
@benjholla
Copy link
Author

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