为给定的N行数打印以下模式。
N=4的
模式
1
##
234
####输入格式:
整数N(总no.(行)
输出格式:
N行中的
模式
Constraints:
N位于范围: 1,20
示例输入:
5
示例输出:
1
##
234
####发布于 2022-04-06 05:15:32
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
int val = 1;
for (int row = 1; row <= N; row++) {
if (row % 2 == 0) {
// Print special character, row number of times
for (int col = 1; col <= row; col++) {
System.out.print("#");
}
} else {
// Print val, row number it times, increment it continuously
for (int col = 1; col <= row; col++) {
System.out.print(val);
val++;
}
}
System.out.println();
}
scn.close();
}
}https://stackoverflow.com/questions/71761349
复制相似问题