Skip to content

Instantly share code, notes, and snippets.

@pebosi
Created April 30, 2014 21:25

Revisions

  1. pebosi created this gist Apr 30, 2014.
    19 changes: 19 additions & 0 deletions Collatz.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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);
    }
    }