-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimefind.java
More file actions
34 lines (23 loc) · 786 Bytes
/
primefind.java
File metadata and controls
34 lines (23 loc) · 786 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
import java.util.*;
public class primefind {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter your index ");
// this is for input
int a = sc.nextInt();
System.out.println("they are prime no between 1 to " + a + "\n");
// i for counting till input
for (int i = 1; i <= a; i++) {
int count = 0; // this is show the number is prime or not
for (int num = i; num >= 1; num--) {
if (i % num == 0) {
count = count + 1;
}
}
if (count == 2) {
// code that append prime number
System.out.print(i + " , ");
}
}
}
}