Skip to content

Instantly share code, notes, and snippets.

@jpboudreault
Created February 19, 2013 20:33
Show Gist options
  • Save jpboudreault/4989669 to your computer and use it in GitHub Desktop.
Save jpboudreault/4989669 to your computer and use it in GitHub Desktop.
Java Land Magical unicorn 3
import java.util.HashSet;
import java.util.Set;
public class MagicalLand {
public static void main(String[] args) {
for (int i = 0; i < (Math.random() * 500) + 2; i++) {
if (Unicorn.pat()) {
System.out.println("UNICORN #1: PAT THIS UNICORN ONCE");
}
}
for (int i = 0; i < (Math.random() * 500) + 2; i++) {
if (Unicorn.pat()) {
System.out.println("UNICORN #2: PAT THIS UNICORN ONCE");
}
}
System.out.println("END OF PROGRAM");
}
public static class Unicorn {
public static boolean pat() {
return true;
}
}
private static class System {
public static Out out = new Out();
}
public static class Out {
private static Set<String> printed = new HashSet<String>();
public static void println(String s) {
if (!printed.contains(s)) {
printed.add(s);
java.lang.System.out.println(s);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment