Java - print all numbers from 1-1000 that are divisible by both 3 and 5

Description

print all numbers from 1-1000 that are divisible by both 3 and 5

Demo

/**
 * print all numbers from 1-1000 that are divisible by both 3 and 5
 *///from ww w  . j a  v a 2s.  c  o m

public class DivisibleNumbers {

  public static void main(String args[]) {
    for (int i = 1; i <= 1000; i++) {
      boolean divisible = true;

      if (i % 3 != 0 || i % 5 != 0) {
        divisible = false;
      }

      if (divisible) {
        System.out.println(i);
      }
    }
  }
}

Related Topic