我要输出*的三角形就像这样:使用for循环输出*的三角形的
*
**
***
这是我的代码:
public class triangleStars {
public static void main(String[] args) {
for(int N=0 ; N<=3 ; N=N+1)
{
for(int M=0 ; M!=N ; M=M+1)
{
System.out.println("*");
}
System.out.println();
}
}
}
如果我运行代码我在彼此之间得到星星,并在两行之间添加一行,并在每行之后添加一颗星星。我错过了什么?内环的
使用'print',而不是'在内环println'。 –
要给Andy的评论添加一些上下文,'println'会打印出你给它的结果(可选),然后换行。 'print'只是打印没有附加新行的字符串。 –
这是一个功课题吗?如果是这样,请阅读https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions –