how to use math.pi in java

前端 未结 4 1146
长情又很酷
长情又很酷 2021-02-03 19:58

I am having problems converting this formula V = 4/3 π r^3. I used Math.PI and Math.pow, but I get this error:

\';\

4条回答
  •  再見小時候
    2021-02-03 20:30

    Here is usage of Math.PI to find circumference of circle and Area First we take Radius as a string in Message Box and convert it into integer

    public class circle {
    
        public static void main(String[] args) {
            // TODO code application logic here
    
            String rad;
    
            float radius,area,circum;
    
           rad = JOptionPane.showInputDialog("Enter the Radius of circle:");
    
            radius = Integer.parseInt(rad);
            area = (float) (Math.PI*radius*radius);
            circum = (float) (2*Math.PI*radius);
    
            JOptionPane.showMessageDialog(null, "Area: " + area,"AREA",JOptionPane.INFORMATION_MESSAGE);
            JOptionPane.showMessageDialog(null, "circumference: " + circum, "Circumfernce",JOptionPane.INFORMATION_MESSAGE);
        }
    
    }
    

提交回复
热议问题