Solution for Hailstone Numbers in Java 8


Dec. 18, 2019 11.115456 seconds Java 8
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);
 
    }
  
    
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.