PI

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes.

PI

Don't be discouraged. Usually things work as you expect. If you can do math with an electronic calculator then you can do it with Java. Occasionally there are annoying details, but that is true of calculators, also.

Here is another excerpt from the Java documentation:

PI

public static final double PI

The double value that is closer than any other to pi, 
the ratio of the circumference of a circle to its diameter.

The reserved word final in this means that the value PI will not change.

Often you need the value π in a program. The way to get it is to say Math.PI (the PI must be upper case). Here is an example:

double x = Math.PI;

QUESTION 18:

Java has trigonometic functions, just like a calculator. For example it has the function Math.cos().

Do you expect that the argument to Math.cos() to be in radians or in degrees?