-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritPrime.java
More file actions
68 lines (53 loc) · 1.45 KB
/
InheritPrime.java
File metadata and controls
68 lines (53 loc) · 1.45 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
program to find prime numbers from an array in one class and print them in another class
*/
/*
@ author : saurabh vaish
*/
import java.util.Scanner;
class cPrime {
static int ar[] = new int[6];
static int cp[] = new int[6];
static int pr[] = new int[6];
void init() {
Scanner sc = new Scanner(System.in);
String s[] = sc.nextLine().split(" ");
for (int i = 0; i < s.length; i++) {
ar[i] = Integer.parseInt(s[i]);
}
}
int j=0,k=0;
void checkPrime() {
for (int a : ar) {
int c = 0;
for (int i = 2; i < a / 2; i++) {
if (a % i == 0) {
c++;
// break;
}
}
if (c == 0) {
pr[j] = a;
// System.out.println(pr[j]);
j++;
} else {
cp[k] = a;
// System.out.println(cp[k]);
k++;
}
}
}
}
public class InheritPrime extends cPrime
{
public static void main(String[] args) {
InheritPrime ip = new InheritPrime();
ip.init();
ip.checkPrime();
for (int i:pr)
{
if(i!=0&&i!=1)
System.out.println(i);
}
}
}