ChrisTheHedgehog
ChrisTheHedgehog

Reputation: 1

How can I get this program to print out ten items per line seperated by 1 space?

Here's my code so far

public class DivisibleBy5and6
{
   public static void main (String []args)
   {
      for (int i = 100; i <= 200; i++)
      {
         boolean num = (i % 5 == 0 || i % 6 == 0) && !(i % 5 == 0 && i % 6 == 0);

         if (num == true)
            System.out.println(i + " is divisible");
      }
   }
}

Like stated previously how can I get the output to print out 10 items per line separated by a space?

Upvotes: 0

Views: 57

Answers (1)

Cody S
Cody S

Reputation: 4824

How about:

int count = 0;
    for (int i = 100; i <= 200; i++) {
        boolean num = (i % 5 == 0 || i % 6 == 0) && !(i % 5 == 0 && i % 6 == 0);

        if (num == true) {
            count++;
            System.out.print(i + " is divisible ");
            if(count >= 10) {
                System.out.println();
                count -= 10;
            }
        }
    }

Upvotes: 1

Related Questions