-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathAllPrime.java
More file actions
33 lines (32 loc) · 741 Bytes
/
AllPrime.java
File metadata and controls
33 lines (32 loc) · 741 Bytes
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
//Program to display all prime numbers in between two given numbers.
import java.util.Scanner;
public class AllPrime
{
public static void main(String args[])
{
Scanner reader = new Scanner(System.in);
System.out.print("\nEnter the Start Number: ");
int startNum = reader.nextInt();
System.out.print("\nEnter the End Number: ");
int endNum = reader.nextInt();
int primeCount = 0;
for (int i = startNum; i <= endNum; i++)
{
boolean test = false;
for (int j = 2; j <i; j++)
{
if (i % j == 0)
{
test = true;
break;
}
}
if (test == false)
{
System.out.print("\nPrime number = " + i);
primeCount++;
}
}
System.out.print("\nTotal number of primes are " + primeCount);
}
}