Skip to content

Instantly share code, notes, and snippets.


benjholla/ Secret

Created Sep 10, 2018
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));

This comment has been minimized.

Copy link
Owner Author

@benjholla benjholla commented Sep 10, 2018

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