求助!!如何用JAVA语言用循环结构打出一个图形来?

来源:百度知道 编辑:UC知道 时间:2024/06/25 00:33:07
比如说这个:

*
**
***
****
*****
******
*******
*********
**********
***********
************
*************

具体代码怎么写? 谢谢了

public class sjx {
public static void main(String[] args) {
int row=10;
for (int i = 0; i < row; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}

public class Sanjiao{
public static void main(String args[]){
for(int i=1;i<10;i++){
for(int j=1;j<i+1;j++){
System.out.print("x");}
System.out.print();}
for(int m=8;m>0;m--){
for(int n=1;n<m+1;n++){
System.out.print("x");}
System.out.print();}
}
}

太简单了..
int n = 5;//5行
for (int i = 0; i < n; i++) {
for (int j = 0; j < i * 2 + 1; j++) {
System.out.print("*");
}
System.out.println();
}

哦..我写的是1 3 5 7 .... 没看清楚 你的是 1 2 3 4 .. 楼上正解、