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

📄 roots.java

📁 使用Java 编写求一元方程的根,并且是使用小程序完成的
💻 JAVA
字号:
import javax.swing.*;
public class roots
{
	public static void main(String args[])
		{
			double a,b,c,deta;
			double x1,x2;
			a=Double.parseDouble(JOptionPane.showInputDialog("Enter an amout in double,for example 11.25"));
            b=Double.parseDouble(JOptionPane.showInputDialog("Enter an amout in double,for example 11.2"));
            c=Double.parseDouble(JOptionPane.showInputDialog("Enter an amout in double,for example 1.25")); 
			deta=b*b-4*a*c;
			if(deta==0)
				{
					x1=(-b)/(2*a);
					x2=x1;
					System.out.println("x1="+x1);
					System.out.println("x2="+x2);
				}
				else if(deta>0)
				{
						x1=(-b+(float)Math.sqrt(deta))/(2*a);
						x2=(-b-(float)Math.sqrt(deta))/(2*a);
						System.out.println("x1="+x1);
						System.out.println("x2="+x2);
				}
				else if(deta<0)
					    System.out.println("equation no real root");
					    
		}
} 

⌨️ 快捷键说明

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