Computer Applications

Write a program that displays all the numbers from 150 to 250 that are divisible by 5 or 6, but not both.

Java

Java Iterative Stmts

3 Likes

Answer

public class KboatFactorCheck
{
    public static void main(String args[]) {

        for (int i = 150; i <= 250; i++) {
            int mod5 = i % 5;
            int mod6 = i % 6;
            
            if ((mod5 == 0 || mod6 == 0) 
                    && !(mod5 == 0 && mod6 == 0)) {
                System.out.println(i);
            }
        }
    }
}

Output

Answered By

2 Likes


Related Questions