+ 2

How to convert this algebraic expression 4/3 pi r^3 to java expression where pi=22/7

29th Nov 2019, 4:27 AM
ELSYA RYENNA HENRY
3 Réponses
+ 10
elsya ryenna you can use maths library like this way and use value of PI by this "Math.PI" import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc= new Scanner (System.in); double Area, Radius; System.out.println("Enter value of radius: "); Radius= sc.nextDouble(); Area= (4/3)*Math.PI*(Radius*Radius*Radius); System.out.println("The area with radio " + Radius+ " is: " + Area); } }
29th Nov 2019, 4:44 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
example above is wrong because ( 4/3) as int type return 0 correct way is (4.0/3.0) double volume= (4.0/3.0)*Math.PI*(Radius*Radius*Radius);
29th Nov 2019, 7:01 PM
zemiak
0
Thank you for helping me👍
16th Dec 2019, 8:55 AM
ELSYA RYENNA HENRY