Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Collatz {
- public static void main(String[] args) {
- System.out.println(collatz(0, 17));
- }
- public static int collatz(int count, int num){
- if(num == 1) return count;
- else if(num % 2 == 0) return collatz(count+1, num/2);
- else return collatz(count+1, (num*3)+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment