【发布时间】:2016-01-08 22:20:09
【问题描述】:
我想通过对 lops 和/或 if 语句使用嵌套来打印它
ABABABAB
BABABABA
ABABABAB
BABABABA
ABABABAB
BABABABA
ABABABAB
BABABABA
public class chess {
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i=0; i<4; i++)
{
for (int r = 0; r < 1; r++)
{
if (r%2== 0)
{
System.out.print("A");
}
if (r%2==1)
{
System.out.print("B");
}
}
for (int x = 0; x < 1; x++)
{
if (x%2== 0)
{
System.out.print("B");
}
if (x%2 == 1)
{
System.out.print("A");
}
}
}
}
}
输出只是:ABABABAB
我不想只是来回做System.out.println("BABABABA")。
谢谢!我是编码新手,不胜感激。
【问题讨论】:
-
I don't want to just do System.out.println("BABABABA").. 你想用什么? -
嵌套 for 循环和/或 if 语句
-
将
x < 1和r < 1更改为x < 8和r < 8
标签: java if-statement for-loop printing