0

Sum of prime numbers upto 10

please explain step by step

15th Mar 2017, 10:03 AM
Varun Singh
Varun Singh - avatar
3 ответов
+ 2
A number is a prime, if its not divisible by any number. Hence in this foe loop, you have your number divided by every numbee less than the number itself. If it is divisible, Return true or false.
15th Mar 2017, 10:17 AM
Meharban Singh
Meharban Singh - avatar
+ 1
  public class Main {       public static void main(String args[]){                   int number = 2;         int count = 0;         long sum = 0;         while(count < 10){             if(isPrimeNumber(number)){                 sum += number;                 count++;             }             number++;         }         System.out.println(sum);     }           private static boolean isPrimeNumber(int number){                   for(int i=2; i<=number/2; i++){             if(number % i == 0){                 return false;             }         }         return true; }
15th Mar 2017, 10:13 AM
Varun Singh
Varun Singh - avatar
0
provide code
15th Mar 2017, 10:09 AM
Meharban Singh
Meharban Singh - avatar