forked from aromalsanthosh/Java-Lab-S3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintPrime.java
More file actions
36 lines (28 loc) · 829 Bytes
/
PrintPrime.java
File metadata and controls
36 lines (28 loc) · 829 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
34
35
36
//Java Program to Print Prime Numbers upto N
import java.util.Scanner;
class PrintPrime{
PrintPrime(int maxNumber){
System.out.println("List of the prime number between 1 - " + maxNumber);
for (int num = 2; num <= maxNumber; num++)
{
boolean isPrime = true;
for (int i=2; i <= num/2; i++)
{
if ( num % i == 0)
{
isPrime = false;
break;
}
}
if ( isPrime == true )
System.out.print(num+" ");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
System.out.println("Enter value Of N upto which prime numbers are to be printed :");
num = sc.nextInt();
new PrintPrime(num);
}
}