-1

我想带上我的三次函数计算器,并有可能使用度数。我将如何更改代码来做到这一点?

    c.println("Welcome to this program which will help you solve a cubic function");    //top text
c.println ("");
c.println("Please enter coefficients in the following form");                       //explaining the format
c.println("f(x) = ax^3 + bx^2 + cx + d");


c.print(" Enter your X value: ");               //asking for the x value
double x = c.readDouble();

c.print("Enter your first coefficient (a): ");  //asking for the x value
double a = c.readDouble();

c.print("Enter your second coefficient (b): "); //asking for the x value
double b = c.readDouble();


c.print("Enter your third coefficient (c): ");  //asking for the x value
double c1 = c.readDouble();

c.print("Enter your last coefficient (d): ");   //asking for the x value
double d = c.readDouble();

c.println(CubicFunction(x,a,b,c1,d),0,2);       //prints out the final result, rounded to 2 decimals
c.println ("");

int choice = 1; // initializes choice to 1 so it can enter the main loop

while (done == false)   //main loop
4

2 回答 2

0

看起来您的CubicFunction方法进行了计算并返回了结果。您需要修改此代码以执行不同的计算或返回不同的结果。您上面提供的代码实际上根本不进行任何计算。

将方法的名称更改为CubicFunction以小写字母开头(即cubicFunction)可能也是一个好主意,或者可能将其命名为更有意义的名称(即calculateCubicFunction)-您的代码让我感到困惑,我认为CubicFunction这是一个类。

于 2012-10-19T01:08:12.963 回答
0

使用 java.lang.Math 类访问三角函数

于 2012-10-19T01:08:27.420 回答