我希望我的程序呈三角形,空间在下面的照片之间。 继承人我的代码到目前为止。显示使用子字符串方式使用星号的三角形形状
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String space= " ";
space.replaceAll("", " ");
int i = input.nextInt();
while (i > 0) {
for (int j = 0; j <1; j++)
System.out.print("*"+space.substring(0,0)+"*");
System.out.println();
i--;
}
}
当我运行这段代码的输出是这样的
**
**
**
**
**
**
**
**
**
我想输出看起来像这样:
的
你需要第一个还是第二个输出? –
第二个输出 – mrorgon