gpt4 book ai didi

java - while 循环输出不完整

转载 作者:行者123 更新时间:2023-12-01 16:39:03 25 4
gpt4 key购买 nike

我应该给出这个输出

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

依此类推5次迭代但它只显示前 2 个输出

这是我的代码

public class itiration {

public static void main( String args[]){

int counter1 = 1;
int counter2 = 1;
int counter3 = 1;

while(counter1<=5)
{

while(counter2<=5)
{
System.out.print("* ");
System.out.print(" ");
counter2++;
}

System.out.println();

while(counter3<=5)
{
System.out.print(" ");
System.out.print("* ");
counter3++;
}


System.out.println();

counter1++;
}

}

}

这不是作业

最佳答案

您是否尝试过使用调试器单步调试该程序?

提示:外循环执行第一次迭代后,counter2和counter3的值是多少?

关于java - while 循环输出不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com