We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5ae4b25 commit 2fb6202Copy full SHA for 2fb6202
NumOfFactors/NumOfFactors.java
@@ -0,0 +1,28 @@
1
+
2
+public class NumOfFactors {
3
4
5
+ public static void main(String[] args) {
6
7
+ long number=10;
8
+ int factors=getNumOfFactors(number);
9
10
+ System.out.println(String.format("Total factors of %d are: %d",number,factors));
11
+ }
12
13
+ private static int getNumOfFactors(long num) {
14
15
+ int totalFactors=1;//accounts for the number itself
16
+ int increment=1;
17
+ if(num%2==1) {//if number is odd, it can never have an even factor
18
+ increment=2;
19
20
21
+ for(long numFac=1; numFac<num ; numFac+=increment) {
22
+ if(num%numFac==0) {
23
+ totalFactors+=1;
24
25
26
+ return totalFactors;
27
28
+}
0 commit comments