public class ThreeNPlus1 { public static int getCycle (int n){ int count =1; while(n != 1){ if( n % 2 ==0) n/=2; else n = n*3+1; count++; } return count; } public static int getMaxCycle(int i, int j){ int maxCycle= -1; int maxNum = i; for(int k = i;k<=j;k++){ int cycle = getCycle(k); if( cycle > maxCycle){ maxCycle = cycle; maxNum = k; } } return maxCycle; } public static void main(String[] args){ System.out.println("1 10 " + getMaxCycle(1,10)); System.out.println("100 200 " + getMaxCycle(100,200)); System.out.println("201 210 " + getMaxCycle(201,210)); System.out.println("900 1000 " + getMaxCycle(900,1000)); } }