pages:
  • 1
MMBs of IAUT SAYS

import java.util.*; public class Main {

public static void main(String[] args) {
    Scanner inp = new Scanner(System.in);

    boolean flag=true;
    int [] a = new int [0];
    int i=1,c=0;
    int n=inp.nextInt();
    if (n>0)
    while (flag){

    while (n>1){
        if (n%2==0){
            n=n/2;
            i++;
        }
        else {
            n=(n*3)+1;
            i++;
        }

    }

     a=java.util.Arrays.copyOf(a, a.length+1);

    a[c++]=i;
    n=inp.nextInt();
    i=1;
     if(n>0)
         flag=true;
     else
         flag=false;
    }
for(int x=0;x<a.length;x++)    
System.out.println(a[x]);
}

}

AMiR SAYS

Please post your code in code format. For god's sake!!!

.::::. SAYS

include

int main(){

int a,i;
while(std::cin>>a&&a!=0){
    for(i=1;a!=1;i++)
        if(a%2==0)
            a/=2;
        else
            a=a*3+1;
    std::cout<<i<<"\n";}

}