**New course!**Every coder should learn

**Generative AI!**

+ 2

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

3 Answers

+ 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);
}
}

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);

0

Thank you for helping me👍