多多的数字组合(Java)
https://www.nowcoder.com/exam/test/82584972/detail?pid=30579184
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public int method(){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if(N<=0 || N>45){ return -1; } String out_str = ""; int max_num = 9; while(N>0){ if(N>max_num){ N = N-max_num; out_str = max_num+out_str; max_num--; }else { out_str = N+out_str; break; } } int out = Integer.parseInt(out_str); return out; } public static void main(String[] args) { Main m = new Main(); System.out.println(m.method()); } }