543212345 4321234 32123 212 1 java循环嵌套如何写?谢谢!
1个回答
展开全部
package Loop;
public class Loop
{
public static void main(String[] args)
{
int value = 5;
boolean tag = false;
for(int i = 0;i < 5; i++)
{
for(int j = -value;j <= value;j ++)
{
if(j == 0)
{
continue;
}
if(j == 1 && tag == false)
{
tag = true;
continue;
}
if(tag == true)
{
tag = false;
}
System.out.print(Math.abs(j));
}
System.out.print(" ");
value --;
}
}
}
public class Loop
{
public static void main(String[] args)
{
int value = 5;
boolean tag = false;
for(int i = 0;i < 5; i++)
{
for(int j = -value;j <= value;j ++)
{
if(j == 0)
{
continue;
}
if(j == 1 && tag == false)
{
tag = true;
continue;
}
if(tag == true)
{
tag = false;
}
System.out.print(Math.abs(j));
}
System.out.print(" ");
value --;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询