-1

I would like to write "if i is a multiple of 11" then

System.out.print("|")

But I'm not sure how to do this?

I'm trying to incorporate sides on the edge of my 'tank of fish'.

The situation might be silly but I think the question is valid.

--------------------------------------------------
<#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#><
<#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#><
<#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#><
<#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#>< <#><
<#>< <#>< <#><
----------------------------------------------------

public class partCC
{

    public partCC()
    { 
    System.out.println("--------------------------------------------------");
    {
    for (int i=0; i<43; i++)



     {if (i > 0 && i%10 == 0)  
        System.out.println(); 

        System.out.print(" <#><");

    }
    {if 
       (i

      System.out.println();
      System.out.print("----------------------------------------------------");
    }


    } 
}
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Kerry G
  • 917
  • 4
  • 12
  • 21

3 Answers3

3

It think you should look at How Does Modulus Divison Work just to understand why this answer is right.

the answer in your case is if ((i % 11) == 0) { System.out.print("|") }

Community
  • 1
  • 1
eyossi
  • 4,230
  • 22
  • 20
2

if ((a % b) == 0) System.out.print("|");

The modulus operator % returns the remainder after dividing a by b which will always be 0 if a is divisible by b.

eyossi
  • 4,230
  • 22
  • 20
PoeHaH
  • 1,936
  • 3
  • 28
  • 52
1

You need to check for the Zero in condition

if(i != 0 && (i % 11) == 0) System.out.print("|");

because initializing i with zero would produce | at first loop cycle too as 0 % 11 would produce 0

Junaid
  • 2,084
  • 1
  • 20
  • 30