Reputation: 1
How can I create an application that can display the square root of a number submitted as an argument? So far I have:
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));
}
}
But I am obviously missing something according to run time error. `error.
Upvotes: 0
Views: 375
Reputation: 19185
Your paint method is incorrect. Replace it with below. drawString
accepts three parametersString
, 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);
}
Upvotes: 2