-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimeNumber.java
50 lines (34 loc) · 1.01 KB
/
PrimeNumber.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
38
package Assignment2;
import java.util.Scanner;
public class PrimeNumber {
public static void main(String args[]) {
int i, s, j, p;
int arr[] = new int[100];
Scanner sc = new Scanner(System.in);
System.out.print("Enter size of an array:");
s = sc.nextInt();
System.out.print("Enter array elements:");
for (i = 0; i < s; i++) {
arr[i] = sc.nextInt();
}
System.out.println("All prime numbers are:");
for (i = 0; i < s; i++)
{
j = 2;
p = 1;
while (j < arr[i])
{
if (arr[i] % j == 0)
{
p = 0;
break;
}
j++;
}
if (p == 1)
{
System.out.print(" " + arr[i]);
}
}
}
}