import java.util.*;
public class Ch2Q24
{
public static void main(String[] args)
{Scanner kbd = new Scanner(System.in);
int no, count = 0;
System.out.print("Enter the integer: ");
no = kbd.nextInt();
while(no != 1)
{ if(no%2 != 0)
no = 3*no + 1;
else no/=2;
System.out.print(no+ " ");
count++;
}
System.out.println("\nNo of iterations = "+count);
}
}
No comments:
Post a Comment