ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2017 ICSE Computer Science Paper



Share with a Friend

Solved 2017 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Sum of Prime Numbers Program - ICSE 2017 Specimen Computer Science

Write a program to calculate the sum of all the prime numbers between the range of 1 and 100.

import java.io.*; class Prime{ public static void main(String args[]){ int sum = 0; for(int i = 1; i <= 100; i++){ int f = 0; for(int j = 1; j <= i; j++){ if(i % j == 0) f++; } if(f == 2) sum += i; } System.out.println("Sum = " + sum); } }

Output

 
 OUTPUT : 
 Sum = 1060