Tôi gặp sự cố khi chuyển đổi công thức này V = 4/3 π r3
. Tôi đã sử dụng Math.Pi
và Math.pow
, nhưng đó là nơi vấn đề bắt đầu. Tôi gặp lỗi này (mọi lúc),cách sử dụng math.pi trong java
';' dự kiến
Ngoài ra, biến đường kính không hoạt động. Có lỗi ở đó không?
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 ");
}
}
Vấn đề tiếp theo bạn sẽ gặp được trả lời ở đây: http://stackoverflow.com/questions/10455677/division-in-java –