by Dinesh Thakur Category: Operators and Expressions

Most of the computer languages typically support advanced math operations (such as square root, trigonometric sine, cosine etc.) by way of function libraries. Java also provides a range of methods that support such functions in the standard libraries Math class stored in the package java.lang. Java's Math class contains a collection of methods and two constants that compute standard mathematical functions.

All the methods and constants available in the Math class are static; so they can simply be referred by just writing class name Math and name of the method or constant you want to use separated by a period (.)

//Program to Show various Methods of Math Class

public class MathematicalOperations

{

public static void main(String [] args)

{

System.out.println("Absolute value -16 = " + Math.abs(-16));

System.out.println("Sine of va1ue PI/2= " + Math.sin(Math.PI/2));

System.out.println("Arc Cosine of -1 = " + Math.acos(-1));

System.out.println("Upper limit of 7.8 = "+ Math.ceil(7.8));

System.out.println("Lower limit of 7.8 = "+ Math.floor(7.8));

System.out.println("Maximum of 15 and 20 = " +Math.max(15,20));

System.out.println("Rounded value = " + Math.round(7.68));

System.out.println("Square root of 4 = " + Math.sqrt(4.0));

System.out.println("2 power 3 is = " + Math.pow(2.0,3.0));

System.out.println("Log of 1000 = " + Math.log(1000.0));

}

}

About Dinesh Thakur

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article

#### Constant - What is Constant? Type of Constant

#### Java Operator

#### What is Identifiers,Literals,Operator and Separators

#### Increment and Decrement Operators in Java Examples

#### Shift Operators in Java Examples

#### Logical Operators in Java Examples

#### Assignment Operator in Java Example

#### Bitwise Complement Operator Example in Java

#### Conditional Operator in Java with Example

#### Arithmetic Operators in Java Examples

#### Explicit Type Conversion (Type Casting)

#### Bitwise Operators in Java Example

#### Bitwise AND, OR, and XOR Operators in Java Example

#### Relational Operators in Java Example

#### Implicit Type Conversion in Java Example

#### Java Break Statement with Label Example

#### Mathematical Operations in Java Example

#### Area of Triangle in Java Example

#### Java Continue Statement Example

#### Compound Assignment Operators in Java Example

#### Java Continue With Label Example

#### Break Statement Java Example

#### Java Arithmetic Operators Example

#### Java Break Statement Example

#### Comparison Operators in Java Example

Basic Courses

Advance Courses

- Advantages And Disadvantages Of Computer
- What is Hard Disk Drive (HDD)?
- What is Router | Definition of Router
- Routers – What is Router? Characteristics of Routers. Router Protocols
- What is Software | Type of Software | Definition of Software
- What is CPU | CPU Definition | CPU Meaning
- What is LAN (Local Area Network) | Definition of LAN