java math pi_如何在java中使用math.pi

转换这个公式V = 4/3πr3有问题。我使用Math.Pi和Math.pow,但这是问题开始的地方。我得到这个错误(每次),

‘;’ expected

此外,直径变量不起作用。那里有错误吗?

import java.util.Scanner;

import javax.swing.JOptionPane;

public class NumericTypes

{

public static void main (String [] args)

{

double radius;

double volume;

double diameter;

diameter = JOptionPane.showInputDialog("enter the diameter of a sphere.");

radius = diameter / 2;

volume = (4 / 3) Math.PI * Math.pow(radius, 3);

JOptionPane.showMessageDialog("The radius for the sphere is "+ radius

+ "and the volume of the sphere is ");

}

}


版权声明:本文为weixin_42509774原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。