You're missing the multiplication operator. Also, you want to do 4/3 in floating point, not integer math.

volume = (4.0 / 3) * Math.PI * Math.pow(radius, 3);
           ^^      ^
Answer from David Yaw on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to pi.
🌐
CodeGym
codegym.cc › java blog › java math › math.pi in java
Math.PI in Java
December 5, 2024 - “The ratio of a circle’s ... in mathematics.” What is Math.PI in Java? “Math.PI is a static final double constant in Java, equivalent to in Mathematics.”......
Discussions

java - How to use Math.PI and Math.pow - Stack Overflow
I am doing an assignment for my first JAVA programming. So far it has been going well but I am stuck at the last part with using math functions. double radius; double diameter; double volume; Sys... More on stackoverflow.com
🌐 stackoverflow.com
[Java] Using PI question
Math.PI already is a constant. You can and should use it wherever you need it. No need to add another constant or anything else. But, supposedly, your teacher didn't mean for you to use Math.PI but rather something like public static final double PI = 3.141592653; A magic number is a numeric literal with a special meaning, like 3.141592653 - constants should be used for such numbers. Another case is something like public static final MAX_NUMBER_OF_SLOTS = 10; - here the name is more important than the actual value. The name conveys the intent, the value doesn't matter. More on reddit.com
🌐 r/learnprogramming
10
1
February 28, 2018
Calculating of PI from sin() function in Java - Mathematics Stack Exchange
Ok... So I'm trying to finish my school project with processing and I'm wondering if there is a way to calculate PI from sin() like this. But I don't know how to use sin() function with degrees in ... More on math.stackexchange.com
🌐 math.stackexchange.com
March 16, 2017
[Java] Is there any way to access true Pi in Java?
The double data type has only 64 bits to work with, so it's limited in how precise it can be. Math.PI is the best approximation possible with a double, and should be precise enough for pretty much any real-world calculation. There's nothing built-in to java that will give you more digits, but you could calculate it yourself by using the BigDecimal class to represent numbers to whatever arbitrary precision you'd like, and by using one of the pi calculating formulas . More on reddit.com
🌐 r/learnprogramming
7
0
December 13, 2019
🌐
W3Schools
w3schools.com › python › ref_math_pi.asp
Python math.pi Constant
Note: Mathematically PI is represented by π. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, ...
🌐
Instructables
instructables.com › circuits › computers
Calculate Pi in Java! : 12 Steps - Instructables
April 29, 2024 - Calculate Pi in Java!: Pi, a well known number equaling 3.1415926... But how can we actually calculate Pi to such incredible accuracy (105 trillion digits in 2024)? Are they actually measuring pieces of string around circles? No, of course not. They use clever algorithms …
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - System.out.println("The floor of " + x + " is " + Math.floor(x)); System.out.println("The floor of " + y + " is " + Math.floor(y)); // Comparison operators // min() returns the smaller of the two arguments // you pass it System.out.println("min(" + i + "," + j + ") is " + Math.min(i, j)); System.out.println("min(" + x + "," + y + ") is " + Math.min(x, y)); // There's a corresponding max() method // that returns the larger of two numbers System.out.println("max(" + i + "," + j + ") is " + Math.max(i, j)); System.out.println("max(" + x + "," + y + ") is " + Math.max(x, y)); // The Math library defines a couple of useful // constants: System.out.println("Pi is " + Math.PI); System.out.println("e is " + Math.E); // Trigonometric methods.
🌐
Reddit
reddit.com › r/learnprogramming › [java] using pi question
r/learnprogramming on Reddit: [Java] Using PI question
February 28, 2018 -

So I know I can do something like a direct import (not sure if that's the real name) but without importing java.lang.Math I can do a Math.PI and use this value for pi. I have an program where I use it more than once, so I think I should make a constant out of it. Personally I don't know why I can't put a Math.PI wherever I need it, because it seems clear and readable already, but I think for my assignment I need to adhere to this convention of use a number more than once with meaning > make constant.

How can I do that though? I have an import java.lang.Math; at the top of my program. Then in my class (but before my main) I have a public static final double PI = Math.PI;..so was there no need to import the Math package? How should I best do this?

🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Math.html
Math (Java SE 11 & JDK 11 )
January 20, 2026 - If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to pi.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How do I use Math.PI in Java? - TestMu AI Community
March 12, 2025 - I am having trouble using the formula V = 4/3 π r^3 in Java. I tried using Math.PI and Math.pow, but I keep getting this error: ';' expected. Additionally, I’m having issues with the diameter variable. Is there an error there? Here’s my code: 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.showInput...
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Math.html
Math (Java SE 21 & JDK 21)
January 20, 2026 - The double value that is closer than any other to pi (π), the ratio of the circumference of a circle to its diameter. ... The double value that is closer than any other to tau (τ), the ratio of the circumference of a circle to its radius. ... Returns the absolute value of a double value.
🌐
W3Schools
w3schools.com › jsref › jsref_pi.asp
W3Schools.com
new Map clear() delete() entries() forEach() get() groupBy() has() keys() set() size values() JS Math · abs() acos() acosh() asin() asinh() atan() atan2() atanh() cbrt() ceil() clz32() cos() cosh() E exp() expm1() f16round() floor() fround() LN2 LN10 log() log10() log1p() log2() LOG2E LOG10E max() min() PI pow() random() round() sign() sin() sinh() sqrt() SQRT1_2 SQRT2 tan() tanh() trunc() JS Numbers
🌐
Sololearn
sololearn.com › en › discuss › 3172680 › how-do-you-use-math-pi
How do you use Math.PI | Sololearn: Learn to code for FREE!
December 15, 2022 - // as i said, repeat changes in Circles class also, here is correct way for circle class class Circle extends Shape { Circle(int y) { width = y ; } public void area() { double Cir_answer = Math.PI*width*width; System.out.println(Cir_answer); } }
🌐
Study.com
study.com › courses › business courses › business 104: information systems and computer applications
How to Use Pi Constant in Java - Lesson | Study.com
January 15, 2018 - This shows right away that your program will be using math for its calculations. The import code looks like this: ... Even though pi goes on seemingly forever, Java stores the value of pi as a constant, or 3.141592653589793.
🌐
Baeldung
baeldung.com › home › algorithms › java program to estimate pi
Java Program to Estimate Pi | Baeldung
January 8, 2024 - In this tutorial, we’ll see how to calculate pi using Java. We’ll adopt the Monte Carlo algorithm to solve this task. Pi is an irrational number – it cannot be expressed as a simple fraction or definite decimal. We can calculate pi to any desired level of accuracy using various mathematical ...
🌐
O'Reilly
oreilly.com › library › view › javatm-how-to › 9780133813036 › ch06lev2sec5.html
Math Class static Constants PI and E - Java™ How To Program (Early Objects), Tenth Edition [Book]
February 24, 2014 - Math Class static Constants PI and E Class Math declares two constants, Math.PI and Math.E, that represent high-precision approximations to commonly used mathematical constants.... - Selection from Java™ How To Program (Early Objects), Tenth Edition [Book]
Authors   Paul DeitelHarvey Deitel
Published   2014
Pages   1248
🌐
programmerAbroad
programmerabroad.com › home › using the pi number in java
Using the PI number in Java - programmerAbroad
March 14, 2025 - The constant: 3.1415… It can be used in lots of areas like calculating: ... In this post we will see how to use it. Java is equipped with the Math class that has the constant PI defined for us.
🌐
Tom's Guide
forums.tomsguide.com › home › apps › apps general discussion
{JAVA} Calculating PI without using class.math | Tom's Guide Forum
August 17, 2012 - double Pi = 4; bool plus = 0; for (int i = 3; i < 10000000; i += 2) { if (plus) { Pi += 4.0 / i; } else { Pi -= 4.0 / i; } plus = !plus; } ... Does it matter? It would work on many languages. I tested it using Visual C++ compiler. I'm sure you can convert it to Java without any problems.