Instantly share code, notes, and snippets.

@benjholla /Puzzle5.java Secret
Created Sep 10, 2018

Embed
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');
}
word.append("est");
System.out.println(String.format("It's time for a %s.", word));
}
}
@benjholla

This comment has been minimized.

Owner

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