用Java解决方程式

时间:2013-12-18 15:57:20

标签: java equation-solving

猜猜我正试图在eclipse上使用java来解决复杂的方程式。

我在打印输出上有相同的答案。有人可以帮忙吗

Scanner input = new Scanner(System.in);
System.out.print("enter the flr_i value");
double flr_i = input.nextDouble();

System.out.print("enter the  effective  flr_j value ");
double flr_j_eff = input.nextDouble();

System.out.print("enter the number of layer-j frames ref by a layer i-frame");
double M_j_i = input.nextDouble();

double j = 0;
double i = 1;
for (j = 0; j<i; j++ )      
    j *=i;

double flr_i_eff = 1-(1-flr_i)*j*Math.pow((1-flr_j_eff), M_j_i );
System.out.println(" the effective frame loss rate is: "+flr_i_eff);

double sigma = 0;
double l = 0;

double ni=1000;
double avgFLR_F = 0;
while (l <20){
    l++;
    sigma += l; 
}

avgFLR_F = sigma*(ni/(sigma*ni))*flr_i_eff;
System.out.print("the mean frame loss rate is :"+ avgFLR_F);

3 个答案:

答案 0 :(得分:3)

这里有一些逻辑问题

double j = 0;
double i = 1;
for (j = 0; j<i; j++ )      
    j *=i;
// j is always 0 after the loop
// j = 0  =>  double flr_i_eff = 1-(1-flr_i)*j*Math.pow((1-flr_j_eff), M_j_i ) = 1 - 0 = 1

答案 1 :(得分:1)

这段代码:

 double j = 0;
 double i = 1;
 for (j = 0; j<i; j++ )      
     j *=i;

将始终为您提供i=1j=0

我假设这不是你想要的(否则为什么有for循环)

这段代码:

double sigma = 0;
double l = 0;

//double ni=1000;
double avgFLR_F = 0;
while (l <20){
    l++;
    sigma += l; 
}

将始终为您提供l=20sigma=190

答案 2 :(得分:0)

你不能这样做,因为乘法初始化为0,即它总是为0。

double j = 0;
double i = 1;
for (j = 0; j<i; j++ )      
    j *=i;