Nathan Coulas

Hailstone Numbers

hailstone JAVA8 18 Dec, 2019 11.115s 5 points

Source Code

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
        int a = 0, num = in.nextInt();
        
        do{
            if(num != 1){ 
            a++;
            if(num % 2 == 0){
                num /= 2;
            }else{
                num = num * 3 + 1;
            }
          }
        }while(num != 1);
        System.out.println(a);
 
    }
  
    
}