如何创建应用程序 可以显示作为参数提交的数字的平方根吗?到目前为止,我有:
import java.awt.*;
public class RootApplet extends javax.swing.JApplet {
int number;
public void init() {
number = 225;
}
public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("The square root of " + arguments[0] +
" is"
Math.sqrt(number));
}
}
但是我显然根据运行时错误遗漏了一些东西。 `错误。
答案 0 :(得分:2)
您的绘画方法不正确。用下面的替换。 drawString
接受三个参数String
,x pos
,y pos
@Override
public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("The square root of "+number+" - "+(int) Math
.sqrt(number),10,10);
}