打印一个高度为N由#符号填充的楼梯
比如N=6时
打印
#
##
###
####
#####
######
我的解答:
import java.io.*;
import java.util.*;
public class Staircase {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
for(int row = 0; row < N; row ++){
for(int space = 0; space < N - row - 1; space++){
System.out.print(" ");
}
for(int sharp = 0; sharp < row + 1; sharp++){
System.out.print("#");
}
System.out.println();
}
}
}
本文介绍了一个简单的Java程序,用于打印由'#'字符组成的楼梯图案。输入整数N作为楼梯的高度,程序将打印出一个N阶楼梯,每阶比上一阶多一个'#'。
&spm=1001.2101.3001.5002&articleId=51417678&d=1&t=3&u=cf8f59f3cbda4cfdb80f77a4121af74b)
780

被折叠的 条评论
为什么被折叠?



