我想要以下模式的代码 [英] I want the code for the below pattern
本文介绍了我想要以下模式的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
*
**
**
***
***
***
and so on....
我尝试过的事情:
What I have tried:
<pre>
public class Pattern {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i,j,n=6,k;
for(i=0;i<=n;i++) {
for(j=0;j<=i+1;j++) {
System.out.print("* "+"");
j++;
}
System.out.println();
}
}
}
推荐答案
您还需要一次迭代。尝试
You need one more iteration. Try
public class Pattern
{
public static void main(String[] args)
{
int i,j,n=6,k;
for ( i = 0; i < n; ++i)
for(j=0; j <=i; ++j)
{
for (k=0; k<=i; ++k)
System.out.print("*");
System.out.println();
}
}
}
运行程序并检查输出。然后你应该看看有什么问题:
- 每条星星之间有空格
- 星星数不正确
- 多个星星只有一行
Run your program and check your output. Then you should see what is wrong:
- There are spaces between the stars on each line
- The number of stars is not correct
- There is only one line for multiple stars
这篇关于我想要以下模式的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文