我希望输出有9个空格然后是一个星,8个空格然后是两个星,7个空格和3个星等等,直到底部的10个星。 我该如何生成空格?
import java.util.Scanner;
public class ThreeDotTwelvea
{
public static void main(String args[])
{
final int max_rows = 1;
for (int row = 10; row >= max_rows; row--)
{
for (int star = 1; star <= row; star++)
System.out.print ("*");
System.out.println();
}
}
}
答案 0 :(得分:2)
试试这个
public class ThreeDotTwelvea {
final static int NO_OF_ROWS = 10;
public static void main(String[] args) {
for (int i = 0; i < NO_OF_ROWS; i++) {
for (int j = NO_OF_ROWS - i - 1; j > 0; j--) {
System.out.print(" ");
}
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
<强>输出强>