-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewDivisors.java
More file actions
57 lines (41 loc) · 1.16 KB
/
ViewDivisors.java
File metadata and controls
57 lines (41 loc) · 1.16 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
//cbasurto: hw 3 problem 2 ViewDivisors
import java.util.Scanner;
import javax.swing.JFrame;
import java.awt.*;
import java.util.Arrays;
public class ViewDivisors {
public static void main(String[] args)
{
//asking for input from user
System.out.println("Enter a positive integer between 10 and 100: ");
Scanner in = new Scanner(System.in);
int x = in.nextInt();
//constructing integer array of divs
int[] divs = new int[x];
//for loop makes sure that the divisors are everything except 1 and i
for(int i= 1; i<x;i++) {
if(i==1) {
//if i is prime, then divs[i] is 0
divs[i]=0;
}
else {
//call Divisors
divs[i] = Divisors.divisors(i).size()-2;
}
}
divs[0]=0;
divs[1]=1;
//display bar graph in JFrame extension
for (int i= 1; i<x; i++)
{
System.out.println(divs[0]);
}
JFrame f = new JFrame();
f.setSize(500, 300);
f.setTitle("Divisors");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Array2BarGraphComponent component = new Array2BarGraphComponent(divs, 400, 300);
f.add(component);
f.setVisible(true);
}
}