怎么这个在html里输出,没过多久显示就没了?
import java.awt.Graphics; import javax.swing.JApplet; import java.lang.Math; public class CoutnPf extends JApplet{ double i = 0,square = 0,cube = 0; double y = 25;
public void paint(Graphics g) { super.paint(g); g.drawString("number square cube",25,(int)y); for( ; i <= 10 ; i++) { square = Math.pow(i,2.0); cube = Math.pow(i,3.0); g.drawString( i + " " + square + " " + cube ,25,(int)y); y = y + 20; } } }
----------------解决方案--------------------------------------------------------
// try it, 问题出在变量的作用范围上。
import java.awt.Graphics;
import javax.swing.JApplet;
import java.lang.Math;
public class CoutnPf extends JApplet
{
int square = 0,cube = 0;
public void paint(Graphics g)
{
int y = 25;
g.drawString("number square cube",25, y);
for(int i = 0; i <= 10 ; i++)
{
square = i*i;
cube = square*i;
y = y + 20;
g.drawString( i +" " + square +" " + cube , 25, y);
}
}
}
----------------解决方案--------------------------------------------------------