星号梯形控制输出空格
来源:5-3 编程练习
慕仙4530950
2020-04-27 09:37:24
public static void main(String[] args) {
// 输出星号组成的梯形
int m = 1;//外重循环的循环变量
int n = 1;//内重循环的循环变量
System.out.println("输出星号组成的梯形");
for(m=1;m<=5;m++){
n = 1;
for(n=1;n<=m*2+1;n++){
System.out.print("*");
}
System.out.println("");
}
}
得到的结果数量是一样,但是空格上面却没有控制好
1回答
public class StarDemo {
public static void main(String[] args) {
// 输出星号组成的梯形
for(int i=1;i<=5;i++){
for(int j=1;j<=5-i;j++){
System.out.print(" ");
}
for(int j=1;j<=i*2+1;j++){
System.out.print("* ");
}
System.out.println();
}
}
}相似问题
回答 2
回答 2