Created
April 30, 2014 21:25
-
-
Save pebosi/6cb71b4ed8f5adef1f6b to your computer and use it in GitHub Desktop.
Collatz in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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