java - 将数学公式输入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();
}
}
解决方案
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();
}
}
推荐阅读
- c# - 使用 c# 获取 Outlook 2010 和其他版本的 stream_autocomplete_0_GUID
- mysql - 重构查询以使用 MySQL(未知列错误)
- docker - 如何配置 NGINX 以正确获取资源
- python - 如何从 HTML 结构中的 href 内部获取值
- c# - C# 异步 TCP 侦听器套接字不接受连接
- html - 为什么我的 text-align 属性不适用于我的跨度?
- python - 将嵌套数据框转换为多索引
- html5-audio - 音频 HTML5 下载功能障碍映射到 SCM
- google-apps-script - Google Apps 脚本比较范围以查找匹配项
- python - 在 Pandas 中将 DataFrame 插入数据库