这应该是正确的
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 k=1;k<=2*i+1;k++){
System.out.print("*");
}
System.out.println();}
}
}
正在回答 回答被采纳积分+1
public class LoopDemo {
public static void main(String[] args) {
//j:3 5 7 9 11
//a:4 3 2 1 0
/**
* 4=11-7; 11-(j+4) //j=3
* 3=11-8; 11-(j+3) //j=5
* 2=11-9; 11-(j+2) //j=7
* 1=11-10; 11-(j+1) //j=9
* 0=11-11; 11-j; //j=11
*/
for (int j = 3,a=4; j <= 11; j += 2,a--) {
for(int b=10-(j+a);b>=0;b--) {
System.out.print(" ");
}
for (int i = 1; i <= j; i++) {
System.out.print("* ");
}
System.out.println();
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public static void main(String[] args) { // TODO Auto-generated method stub for ( int i= 1 ;i<= 5 ;i++) { for ( int j= 5 -i;j>= 1 ;j--) { System.out.print( " " ); } for ( int k= 1 ;k<= 2 *i+ 1 ;k++) { System.out.print( "*" ); } // for(int j=4;j>=1;j--) { // System.out.print(" "); // } System.out.println(); } } |
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧