首页 > 解决方案 > 将数学公式输入java

问题描述

我有一个问题我无法解决搜索互联网,基本上我需要用户首先输入球体的直径然后返回半径并从那里使用公式(4乘3乘以pi(3.14)乘以半径(从直径计算 - 用户输入)到 3 的幂。另一个非常相似..... 4 乘以 pi (3.14) 乘以半径到 2 的幂。

现在的问题是每次我尝试编译时都会收到错误,即该方法是有损双精度而不是 int 或符号无法识别。

伙计们,任何帮助都会有所帮助,因为我找不到解决方案。

代码如下:

import static java.lang.Math.sqrt;
import static java.lang.Math.abs;
import java.lang.*;
import java.util.Scanner;
import java.util.*;

public class RadiusConverter {

    public class Pi{
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int FirstStep, Diameter, Radius, SecondStep, ThirdStep;

        System.out.println ("Please enter the diameter of the Sphere: ");

        int diameter =scan.nextInt();

        System.out.println ("Your Shpere has a radius of: " + FirstStep);

        int radius = scan.nextInt();

        System.out.println ("The Volume of your Sphere is: " + SecondStep);

        System.out.println("The Surface Area of your Sphere is: " + ThirdStep);

        FirstStep = Diameter / 2;
        SecondStep =  4 / 3 * 3.14 * (int) FirstStep * 3;
        ThirdStep = 4 * 3.14 * (int) Radius * 2;
        Diameter = diameter;
        Radius = radius;
        //------------------------------------------------------------------------
        //
        //
        //-------------------------------------------------------------------------
        scan.close();
    }
}

标签: java

解决方案


      This is the older source code I was using … which also did not work.


      import static java.lang.Math.sqrt;
      import static java.lang.Math.abs;
      import java.lang.*;
      import java.util.Scanner;
       import java.util.*;
      public class RadiusConverter
     {

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

     Scanner scan = new Scanner( System.in );

    double FirstStep, Diameter, Radius, SecondStep, ThirdStep;


 System.out.println ("Please enter the diameter of the Sphere: ");
 double diameter =scan.nextDouble();


 System.out.println ("Your Shpere has a radius of: " + FirstStep);
 double radius =scan.nextDouble();


 System.out.println ("The Volume of your Sphere is: " + SecondStep);

 System.out.println("The Surface Area of your Sphere is: " + ThirdStep);

 FirstStep = diameter / 2;
 SecondStep =  4 / 3 * Math.PI* Math.pow (FirstStep, 3);
 ThirdStep = 4 * Math.PI * radius * Math.pow (2);


//------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------

    scan.close();


}

}


推荐阅读