-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrimeNumbers.java
37 lines (32 loc) · 991 Bytes
/
PrimeNumbers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package primenumbers;
import java.util.Scanner;
public class PrimeNumbers
{
//programm that finds the prime numbers within in a given range and its sum.
public static void main(String[] args)
{
Scanner input = new Scanner(System. in);
System.out.println("enter a start number ");
int start = input.nextInt();
System.out.println("enter a start number ");
int end = input.nextInt();
int sum= 0;
for(int i=start; i <=end; i++ )
{
boolean flag = true;
for (int j=2; j<= i-1; j++)
{
if (i%j==0)
{
flag = false;
break;
}
}
if(flag ==true)
{
sum+=i;
System.out.println("Prime number is " +i);
}
} System.out.println(" the sum of Prime number is "+ sum);
}
}