JAVATM- The Beginnings
The Math class provides several methods which perform mathematical operations, and several useful constants.. All methods and constants are declared static, so an object of class Math never needs to be created.
The Math class defines two constants: PI (for a circle’s circumference) and E (for natural logarithms).
Listing 1 - CalculateCircumference.java
public class CalculateCircumference
public static void main(String args)
DecimalFormat output = new DecimalFormat("##.00");
double diameter = 4.0;
double circumference = diameter * Math.PI;
System.out.println("circumference = " +
circumference = 12.57
Copyright ©2017 by Ralph Lecessi Incorporated. All rights reserved.