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

📄 dich.java

📁 数值算法
💻 JAVA
字号:
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.io.*;
public class Dich extends Frame implements ActionListener
{
	private float a[]={-3.14f+3f,-3.14f/3+3f,3.14f/3+3f};
	private float b[]={-3.14f/3+3f,3.14f/3-0.1f+3f,3.14f+3f};
	private float e=0.01f,MinX;
	int flag=1;
	Button bb;
	public Dich()
	{	
		setLayout(new FlowLayout(FlowLayout.LEFT));
		bb=new Button("DRAW");
		add(bb);
		setSize(700,500);
		setBackground(Color.white);
		bb.addActionListener(this);
	}
	
		
	public void paint(Graphics g)
	{
		float i,x;
		g.drawLine(300,50,300,450);
		g.drawLine(10,250,700,250);
		for(i=a[0];i<=b[2];i=i+0.01f)
		{	
			x=i-3.0f;
			g.drawLine((int)(i*100),(int)(250-Fac(x)*100),(int)(i*100+1),(int)(250-Fac(x+0.01f)*100));
		}	 
	}
	public float Fac(float x)
	{		
		float y;
		y=2*(float)Math.sin(x)-x;
		return y;
	}
	public void Scrawl(float A,float B)
	{	
		int x1,x2,y1,y2;
		Graphics g = getGraphics();
		g.setColor(Color.blue);
		for(int j=0;j<200000000;j++){}		
		x1=(int)(A*100)+300;
		x2=(int)(B*100)+300;
		y1=230;
		y2=230;	
		g.drawLine(x1,y1,x1,y1+40);
		g.drawLine(x2,y2,x2,y2+40);	
		g.drawLine(x1,250,x2,250);
		repaint();
	}
	public void Metic()
	{
		int i;
		for(i=0;i<=2;i++)
		{
			float x,A,B;
			B=b[i]-3f;
			A=a[i]-3f;
			while(B-A>e)
			{
				x=(A+B)/2;
				if(Fac(A)*Fac(x)<0)B=x;
				else A=x;
				System.out.println(A+"   "+B);
				Scrawl(A,B);
			}
			MinX=(A+B)/2;
			System.out.println("第"+(i+1)+"个解为"+MinX);
			System.out.println();
		}		
	}
	public void actionPerformed(ActionEvent eve)
	{
		if(eve.getSource()==bb)
		{
			Metic();
			System.out.println("completed");
		}
	}
	
	public static void main(String[] args)throws IOException
	{
		Dich fuck=new Dich();
		fuck.setVisible(true);
	}
}

⌨️ 快捷键说明

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