⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example32.java

📁 用JavaAppletion实现杨辉三角
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;
public class Example32  extends Applet
{
	Label prompt;
	TextField input;
	int x[][]=new int[20][20];
	int i,j,n=0;
	public void init()
	{
		 prompt=new Label("请输入一个1~20的整数");
	    input=new TextField(3);
		add(prompt); add(input); 
	}
	public void paint(Graphics g)
	{    if(n!=0)
			 for(i=0;i<n;i++)
				 for(j=0;j<=i;j++)
					 g.drawString(Integer.toString(x[i][j],6),10+j*50,50+i*20);
	}
	public boolean action(Event e,Object o)
	{   n=Integer.parseInt(input.getText());
		yfsjx(n);repaint();
		return true;
	}
	public void yfsjx(int m)
	{
		for(i=0;i<n;i++)
			for(j=0;j<=i;j++)
				if(j==0||j==i)
					x[i][j]=1;
		else
			x[i][j]=x[i-1][j-1]+x[i-1][j];
	}
	}
	
		
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -