我如何获取我编写的java代码并使计算能够完成学位?

时间:2012-10-19 00:33:47

标签: java

我想采用我的立方函数计算器,并有可能使用度数。我如何改变代码呢?

    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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

使用java.lang.Math类访问trig函数