目前正在处理一些额外的问题集,似乎被这个问题困住了。我需要做下面的输出:需要在java中循环的帮助
* *
* *
* * * * *
* *
* *
我已经得到了十字架上下来,但我有,中间行的问题,希望有人能帮助我找到答案。继承人到目前为止我的代码(输入设定为5):
public static void drawPlusVersion3(int input){
if (input % 2 != 0) {
for(int c = 0; c < input; c++) {
for(int r = 0; r < input; r++) {
if((c == input/2) || (r == input/2))
System.out.print("*");
if (c == r){
System.out.print("*");
}
else
System.out.print(" ");
System.out.print(" ");
}
System.out.println();
}
}
}
电流输出:
* *
* *
* * ** * *
* *
* *
在此先感谢!
你知道为什么* *你的程序打印它所打印的? – immibis
您是否已经完成了IDE调试器中的代码?这是开始的地方,你应该在发布之前这样做,以便更好地了解哪些行为出乎意料。如果您一次只使用一个调试器,您很可能会发现错误。有了这种类型的问题,如果您在问这里之前应用了良好的调试技巧,那么您将为自己和我们其他人节省大量时间。 –
@immibis我知道代码的作用,但我不知道为什么这些2星粘在一起,并破坏了模式 – Ronald