问题描述
输入数字n,按顺序打印出从1到最大的n位十进制数。
代码
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(Arrays.toString(printBunbers(n)));
}
public static int[] printBunbers(int n) {
char[] temp = new char[n];
for (int i = 0; i < n; i++) {
temp[i] = '9';
}
int maxValue = Integer.parseInt(String.valueOf(temp));
int[] res = new int[maxValue];
for (int i = 0; i < maxValue; i++) {
res[i] = i+1;
}
return res;
}
}