PAT-Basic Level-1001 害死人不偿命的(3n+1)猜想;

import java.util.Scanner;

public class Main {

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

}

你可能感兴趣的:(PAT-Basic,Level,java,PAT,Basic,Level)