Guest User

Untitled

a guest
Mar 20th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.29 KB | None | 0 0
  1. public class Collatz {
  2.     public static void main(String[] args) {
  3.         System.out.println(collatz(0, 17));
  4.     }
  5.    
  6.     public static int collatz(int count, int num){
  7.         if(num == 1)    return count;
  8.         else if(num % 2 == 0)   return collatz(count+1, num/2);
  9.         else    return collatz(count+1, (num*3)+1);
  10.     }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment