Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 8

Conditional Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Count and Sum of Numbers Divisible by 17


17. 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.

import java.util.Scanner;

 

public class DivisibleBy17 {

    public static void main(String[] args) {

 

        int count = 0;

        int sum = 0;

 

        // Check numbers from 501 to 999

        for (int i = 501; i < 1000; i++) {

            if (i % 17 == 0) {

                count++;

                sum += i;

            }

        }

 

        // Output

        System.out.println("Number of integers divisible by 17 = " + count);

        System.out.println("Sum of integers divisible by 17 = " + sum);

    }

}

Output

Number of integers divisible by 17 = 29
Sum of integers divisible by 17 = 21692

Explanation

  • The loop runs from 501 to 999.
  • i % 17 == 0 checks if the number is divisible by 17.
  • count keeps track of how many such numbers exist.
  • sum stores the total of these numbers.
  • Final results are displayed after the loop ends.