奇数和偶数的判断

import java.util.Scanner;
public class jiou
{
public static void main(String[] args){
int i=0;
Scanner reader = new Scanner(System.in);
int n= reader.nextInt();
if(n==0 || n==1){
System.out.println("0");
}


while(n!=1){
if(n%2==0){     \\判断其是否为偶数
n = n/2;
   }
else{
n = (3*n+1)/2;
   }
i++;
}
System.out.println(i);
}
}  

你可能感兴趣的:(ACM练习)