-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathPascal.java
More file actions
48 lines (39 loc) · 956 Bytes
/
Copy pathPascal.java
File metadata and controls
48 lines (39 loc) · 956 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
package pascal;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Pascal extends JFrame
{
public Pascal()
{
setBackground(Color.white);
setTitle("巴斯卡三角形");
setSize(520, 350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
show();
}
private long combi(int n, int r)
{
int i;
long p = 1;
for(i = 1; i <= r; i++)
p = p * (n-i+1) / i;
System.out.println("p=" + p + " n=" + n);
return p;
}
public void paint(Graphics g)
{
final int N = 12;
int n, r, t;
for(n = 0; n <= N; n++)
{
for(r = 0; r <= n; r++)
g.drawString(" " + combi(n, r),
(N-n)*20 + r * 40, n * 20 + 50);
}
}
public static void main(String[] args)
{
Pascal frm = new Pascal();
}
}