forked from suhasdk18/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNUmbers.java
More file actions
29 lines (25 loc) · 776 Bytes
/
PrimeNUmbers.java
File metadata and controls
29 lines (25 loc) · 776 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
package chandana;
import java.util.Scanner;
public class PrimeNUmbers
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer N: ");
int N = scanner.nextInt();
System.out.println("Prime numbers up to " + N + ":");
for (int num = 2; num <= N; num++) {
boolean isPrime = true;
for (int i=2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(num + " ");
}
}
scanner.close();
}
}