当前位置: 代码迷 >> Java相关 >> 怎么这个在html里输出,没过多久显示就没了?
  详细解决方案

怎么这个在html里输出,没过多久显示就没了?

热度:245   发布时间:2005-09-21 12:03:00.0
怎么这个在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; } } }

搜索更多相关的解决方案: html  输出  

----------------解决方案--------------------------------------------------------
// 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 &lt;= 10 ; i++)
    {
      square = i*i;
      cube = square*i;
      y = y + 20;
      g.drawString( i +"      " + square +"      " + cube , 25, y);
      
    }
  }   
}
----------------解决方案--------------------------------------------------------
  相关解决方案