-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountDivisor.java
More file actions
38 lines (32 loc) · 985 Bytes
/
CountDivisor.java
File metadata and controls
38 lines (32 loc) · 985 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
import textio.TextIO;
/*
* This program reads a positive integer from the user.
* It count how many divisor that numberhas, and
* then it prints the result.
*/
public class CountDivisor{
public static void main(String[] args) {
int N;
int testDivisor;
int divisorCount;
int numberTested;
while (true){
System.out.println("Enter a positive integer: ");
N = TextIO.getInInt();
if (N > 0);
break;
System.out.println("That number is not positive. please try again.");
}
divisorCount = 0;
numberTested = 0;
for (testDivisor = 1; testDivisor <= N; testDivisor++){
if (N % testDivisor == 0)
divisorCount ++;
numberTested ++;
if (numberTested == 10000000){
System.out.print('.');
numberTested = 0;
}
}
}
}