Ho problemi a convertire questa formula V = 4/3 π r3
. Ho usato Math.Pi
e Math.pow
, ma è qui che inizia il problema. Ottengo questo errore (ogni volta),come usare math.pi in java
';' previsto
Inoltre, la variabile diametro non funziona. C'è un errore lì?
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 ");
}
}
Il problema successivo si incontrano trova risposta qui: http://stackoverflow.com/questions/10455677/division-in-java –