mymath.java

来自「Spring2.0宝典」· Java 代码 · 共 59 行

JAVA
59
字号
package lee;

import java.lang.Math;

/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class MyMath
{
    public double oneEquation(double a , double b)throws MyMathException
	{
		if (a == 0)
		{
			System.out.println("参数错误");
			throw new MyMathException("参数错误");
		}
		else
		{
			return -b/a;
		}

    }

    public double[] twoEquation(double a , double b , double c)throws MyMathException
	{
		double[] result ;
		if (a == 0)
		{
			System.out.println("参数错误");
			throw new MyMathException("参数错误");
		}
		else if(b * b - 4 * a * c < 0)
		{
			System.out.println("方程在有理数范围内无解");
			result = null;
			return result;
		}
		else if(b * b - 4 * a * c == 0)
		{
			System.out.println("方程在有唯一解");
			result = new double[1];
			result[0] = -b/(2 * a);
			return result;
		}
		else
		{
			System.out.println("方程在有两个解");
			result = new double[2];
			result[0] = (-b + Math.sqrt(b * b - 4 * a * c))/2/a;
			result[1] = (-b - Math.sqrt(b * b - 4 * a * c))/2/a;
			return result;
		}
    }
}

⌨️ 快捷键说明

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