KnowledgeBoat Logo

Computer Applications

Write a program to find the number of and sum of all integers greater than 500 and less than 1000 that are divisible by 17

Java

Java Conditional Stmts

16 Likes

Answer

public class KboatDivisibleBy17
{
    public static void main(String args[]) {
        int sum = 0, count = 0;
        for (int i = 501; i < 1000; i++) {
            if (i % 17 == 0) {
                count++;
                sum += i;
            }    
        }
        System.out.println("Sum = " + sum);
        System.out.println("Count = " + count);
    }
}

Output

BlueJ output of Write a program to find the number of and sum of all integers greater than 500 and less than 1000 that are divisible by 17

Answered By

5 Likes


Related Questions