-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek2a.java
More file actions
34 lines (33 loc) · 953 Bytes
/
Week2a.java
File metadata and controls
34 lines (33 loc) · 953 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.ArrayList;
import java.util.Scanner;
public class Week2a {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Enter Size of the Array :");
ArrayList<Integer> x = new ArrayList<>();
int i, n, j, c;
n = reader.nextInt();
int[] a = new int[n];
for (i = 0; i < n; i++) {
a[i] = reader.nextInt();
}
for (i = 0; i < n; i++) {
c = 0;
for (j = 1; j <= a[i]; j++) {
if (a[i] % j == 0) {
c++;
}
}
if (c == 2) {
if (a[i] % 2 != 0) {
x.add(a[i]);
}
}
}
if (x.isEmpty()) {
System.out.println("Not found");
} else {
for (int t : x) System.out.println("Odd and Prime No. : " + t);
}
}
}