Skip to content

Instantly share code, notes, and snippets.

@remexre
Created June 20, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remexre/b531f2ce601217bb846845995579a91d to your computer and use it in GitHub Desktop.
Save remexre/b531f2ce601217bb846845995579a91d to your computer and use it in GitHub Desktop.
/**
* The main entry point.
*
* TODO Turn this into a Servlet.
*/
public class WhyIHate/*Java*/ {
private static final int TWENTY = 20; // Magic numbers are bad.
// TODO Create a wrapper class to protect i from invalid accesses.
// TODO Create a factory for that wrapper class -- you never know when we
// might need to upgrade the data model.
private static int i = TWENTY;
public static void main(String ... args) {
while(i != 1) {
// TODO Ideally, we'd hide the math here in an inner class. Or
// better yet, create an IIterativeComputation interface and an
// AbstractIterativeComputation class implementing it, then a
// CollatzIterativeComputation class with a
// CollatzIterativeComputationBuilder and/or a
// CollatzIterativeComputationFactory to allow for easy
// construction.
i = i % 2 == 0
? i / 2
: i * 3 + 1;
// TODO Create a proper output stream delegate bean interface.
System.out.println(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment