参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int x = scanner.nextInt(); while(x != 1) { if(x % 2 == 0) { System.out.printf("%d/2=%d\n", x, x / 2); x /= 2; }else { System.out.printf("%d*3+1=%d\n", x, x * 3 + 1); x = x * 3 + 1; } } } }
0.0分
5 人评分