Class Object and Method
 
Example of the Math class
 
Different methods in the Math Class:
 
 
 
Sample programs
The following small samples will help us understand how easy it is to use the class methods of the Math class:
 
Example 1:
Performing some miscellaneous mathematical calculations on a number
 
public class AppMath
{
public static void main(String[] args)
{

double x;
char again;

do
{
Utility.separator(50, '~');
System.out.print("Enter a number: ");
x = Keyboard.readDouble();
Utility.skip();
System.out.println(" Ceiling = " + Math.ceil(x));
System.out.println(" Floor = " + Math.floor(x));
System.out.println(" Rounded = " + Math.round(x));
System.out.println(" Squared = " + Math.pow(x, 2));
System.out.println(" Square root = " + Math.sqrt(x));
Utility.skip();
System.out.print("Again? (Y/N): ");
again = Keyboard.readChar();
}
while (again == 'Y' || again == 'y');
}
}