0

我尝试运行我的代码,每次我执行 Aquarius Facilitator 时都会显示 0.000。它与 int 和 double 作为我的变量和导致我对 trunkaid 的回答的 int 有关吗?谢谢您的帮助

这是我的程序

public class JRambolus
{
public JRambolus(){}
public JRambolus(double A)
{
    Lengtus = A;
}
public JRambolus(double A, int B)
{
    Lengtus = A;
    Actus   = B;
}
    //mutator
void SetLengtus( double A )
{
    Lengtus = A;
}
    //mutator
void SetActus(int A)
{
    Actus = A;
}
    //accessor 
double GetLengtus()
{
    return Lengtus;
}
    //accessor 
int GetActus()
{
    return Actus;
}
//Facilitator
double Arius()
{ 
    return 3*Lengtus+(1/2*Actus);
}
double Aquarius()
{
    return 4/3*((1/2*Lengtus)+(2/5*Actus));
}
double Nebulus()
{
    return (Math.pow(Lengtus,2)+Math.pow(Actus,3/2))*4/3;
}

//Memeber Varibales
private double Lengtus;
private int Actus;
  }

这是我的调用程序

public class JShower
{
  public static void main(String[] args)
  {

    JRambolus FullRambolus = new JRambolus();

    //Calling out the the system
    System.out.printf("%43s %4s %8.3f%n"    ,"The Arius of FullRambolus is"   ,"=", FullRambolus.   Arius() );
    System.out.printf("%46s %s %8.3f%n"     ,"The Aquarius of FullRambolus is","=", FullRambolus.Aquarius() );
    System.out.printf("%45s %2s %8.3f%n%n%n","The Lengtus of FullRambolus is" ,"=", FullRambolus.Nebulus () );






    JRambolus DefaultRambolus  = new JRambolus();
    //Calling the Mutator From JRambolus
    DefaultRambolus.SetLengtus(6);
    DefaultRambolus.SetActus(3);




    //Calling out to the system
    System.out.printf("%46s %4s %8.3f%n","The Arius of DefaultRambolus is"   ,"=", DefaultRambolus.   Arius() );
    System.out.printf("%49s %s %8.3f%n" ,"The Aquarius of DefaultRambolus is","=", DefaultRambolus.Aquarius() );
    System.out.printf("%48s %2s %8.3f%n","The Nebulus of DefaultRambolus is" ,"=", DefaultRambolus.Nebulus () );




    }
}
4

2 回答 2

0

您正在返回值。看看这里,看看他们如何处理变量的打印/显示。

于 2013-10-01T07:25:26.613 回答
0

您将整数除法与双精度数混合,这可能会导致未执行的结果。

声明应该是

return 4d/3d*((1d/2d*Lengtus)+(2d/5d*Actus));

在您的原始语句中,4/3使用整数除法计算,给出值1. 更关键的是,1/2(result: 0) 和2/5(also zero) 给出的返回值为0.0D

于 2013-10-01T07:31:42.793 回答