package com.xianxian.sushu;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class sushu extends Applet implements ActionListener {
TextField t1 = new TextField(5);
TextField t2 = new TextField(5);
Button b1 = new Button("开始");
int m, n;
public void init() {
add(t1);
add(t2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
m = Integer.parseInt(t1.getText());
n = Integer.parseInt(t2.getText());
repaint();
}
public void paint(Graphics g) {
super.paint(g);
boolean f;
int i, j, k = 0;
for (i = m; i <= n; i++) {
f = true;
for (j = 2; j <= i - 1; j++)
if (i % j == 0) {
f = false;
break;
}
if (f) {
g.drawString(" " + i, (k % 10) * 20 + 20, (k / 10) * 60 + 80);
k = k + 1;
}
}
}
}
素数--java
最新推荐文章于 2024-08-15 14:47:41 发布