-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeFactor.java
More file actions
87 lines (43 loc) · 975 Bytes
/
PrimeFactor.java
File metadata and controls
87 lines (43 loc) · 975 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Jain Aarush
// March 3rd, 2019
// Program: Giving prime factrization of a number
// Mrs.Strelkovska ICS3U7
import java.util.Scanner;
public class PrimeFactor {
public static void main(String[] args) {
System.out.print("Enter an integer: ");
int num1 = 0;
Scanner sn = new Scanner(System.in);
num1 = sn.nextInt();
int num2 = num1;
int primecheck = 0;
for (int i = 1; i < num1; i++) {
if (num1 % i == 0) {
primecheck++;
}
}
if (primecheck == 1) {
System.out.println(num1 + " to the power of 1");
} else {
for (int i = 1; i < num1; i++) {
int newnum = 0;
for (int j = 1; j < (i + 1); j++) {
if (i % j == 0) {
newnum++;
}
}
if (newnum == 2 && num1 % i == 0) {
int times = 0;
while (true) {
num2 /= i;
times++;
if (num2 % i != 0) {
System.out.println(i + " to the power of " + times);
break;
}
}
}
}
}
}
}