import java.util.Scanner;/** * @author:(LiberHome) * @date:Created in 2019/3/6 17:36 * @description: * @version:$ *//*任意给一个大于0的整数N,若N为偶数,将其除以二,若N为奇数将其乘以3再加一;* 编写程序,输入一个N,返回角谷变换(达到1所需)的次数*//*解题思路:用递归*/public class JiaoGuGuess { static int count=0; public static void main(String[] args) { System.out.println("请任意输入一个大于0的整数"); Scanner scanner = new Scanner(System.in); int inputNum = scanner.nextInt(); int result=JGguess(inputNum); System.out.println(""); System.out.println("==========================="); System.out.println("totally exp times: "+result); } private static int JGguess(int num) { if (num%2==0&&num!=0){ System.out.print(" "+num); num=num/2; count++; JGguess(num); }else if (num%2==1&&num!=1){ System.out.print(" "+num); num=num*3+1; count++; JGguess(num); }else if (num==1){ return 0; }else { System.out.print("请输入一个大于0的整数"); return 0; } return count; }}