题解 | #扭蛋机#
扭蛋机
https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String str = ""; while(n > 0){ if (n % 2 == 0){ str += '3'; n = (n - 2) / 2; }else { str += '2'; n = (n - 1) / 2; } } StringBuffer a = new StringBuffer(); for (int i = str.length()-1; i >= 0; i--){ a.append(str.charAt(i)); } System.out.println(a.toString()); } }