Skip to content

Instantly share code, notes, and snippets.

@pebosi
Created April 30, 2014 21:25
Show Gist options
  • Save pebosi/6cb71b4ed8f5adef1f6b to your computer and use it in GitHub Desktop.
Save pebosi/6cb71b4ed8f5adef1f6b to your computer and use it in GitHub Desktop.
Collatz in Java
public class Collatz {
public static void main(String [] argv) {
int x = 100;
int z = 0;
while (x != 1) {
if (x % 2 == 0) {
x = x / 2;
}
else {
x = x * 3 + 1;
}
z++;
}
System.console().writer().println(z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment