Java 使用循环创建特定模式
我试图弄清楚如何使用这种逻辑使我的代码打印出正确的模式Java 使用循环创建特定模式,java,Java,我试图弄清楚如何使用这种逻辑使我的代码打印出正确的模式 Enter len:7 Enter repeat:3 \--\--\ --\--\- -\--\-- \--\--\ --\--\- -\--\-- \--\--\ Bye 这是我写的代码 for(int i = 0; i < len; i++) { for(int j = 0; j < len; j++) { if((j%repeat == 0))
Enter len:7
Enter repeat:3
\--\--\
--\--\-
-\--\--
\--\--\
--\--\-
-\--\--
\--\--\
Bye
这是我写的代码
for(int i = 0; i < len; i++)
{
for(int j = 0; j < len; j++)
{
if((j%repeat == 0))
System.out.print("\\");
else
System.out.print("-");
}
System.out.println();
}
System.out.println("Bye");
我怎样才能让我的工作像这样?通过这些行我知道不同之处在于位置被一个位置关闭,但如何实现这一点是我的问题。for(int I=0;Ifor(int i = 0; i < len; i++)
{
for(int j = 0; j < len; j++)
{
if(((i+j)%repeat == 0))
System.out.print("\\");
else
System.out.print("-");
}
System.out.println();
}
System.out.println("Bye");
{
对于(int j=0;jfor(int i = 0; i < len; i++)
{
for(int j = 0; j < len; j++)
{
if(((i+j)%repeat == 0))
System.out.print("\\");
else
System.out.print("-");
}
System.out.println();
}
System.out.println("Bye");