Java Applet 实现双精度浮点数整数部分提取
import java.awt.; import java.applet.;
public class Prog1 extends Applet { Label label = new Label('请输入一个双精度浮点数:'); TextField input = new TextField(18); Label output = new Label('');
public void init() {
add(label);
add(input);
add(output);
}
public boolean action(Event e, Object o) {
if (e.target == input) {
double inputNumber = Double.valueOf(input.getText());
int integerPart = (int) inputNumber;
output.setText('其整数部分为' + integerPart);
repaint();
return true;
} else {
return false;
}
}
}
原文地址: https://www.cveoy.top/t/topic/oD9t 著作权归作者所有。请勿转载和采集!