Java for loop find numbers divisible by 5 or 6, but not both

Question

We would like to write a program that displays all the numbers from 100 to 200, ten per line, that are divisible by 5 or 6, but not both.

public class Main {

    public static void main(String[] args) {

        int count = 1;
        //your code here
    }
}




public class Main {

    public static void main(String[] args) {

        int count = 1;
        for (int i = 100; i <= 200; i++) {

            if (i % 6 == 0 ^ i % 5 == 0) {
                System.out.print((count++ % 10 != 0) ? i + " " : i + "\n");

            }

        }
    }
}



PreviousNext

Related