# Math

- 28 September
### PI in Java

The Pi is a constant value in Mathematics that represents a floating-point value 3.1415. It is mostly used in geometry to calculate area, circumference, volume, etc. If you have studied geometry in your academic, then you may be aware of use of Pi such as calculating area require this constant value. In Java, when we […]

- 05 October
### Calculate total surface area of Hemisphere in java

In this post, we will see how to calculate total surface area of Hemisphere in java. Hemisphere is exactly half of sphere. There can be many practical examples of Hemisphere. You can divide earth into two hemisphere i.e. Northen Hemisphere and Southern Hemisphere. Formula of calculating total surface area of Hemisphere is: surface area of […]

- 05 October
### Calculate total surface area of Cylinder in java

In this post, we will see how to calculate total surface area of Cylinder in java. Formula of calculating total surface area of Cylinder is: Surface area of Cylinder = 2 *Π * r * r + 2 *Π * r * h Where r is radius of cylinder and h is height of cylinder […]

- 05 October
### Get random number between 0 and 1 in java

In this post, we will see how to get random number between 0 to 1 in java. We have already seen random number generator in java. We can simply use Math.random() method to get random number between 0 to 1. Math.random method returns double value between o(inclusive) to 1(exclusive). [crayon-607c0eaccaec6074305948/] When you run above program, […]

- 03 January
### java round double/float to 2 decimal places

In this post, we will see how to round double to 2 decimal places in java. There are many ways to do it.Let’s go through few ways. Let’s understand each with the help of simple example. Using DecimalFormat You can use DecimalFormat too to round number to 2 decimal places. [crayon-607c0eaccb055393532928/] Output: Rounded double (DecimalFormat) […]

- 03 January
### How to get square root of number in java

In this tutorial. we will see if how to get square root of number in java. It is very simple to get square root of number in java. You can simply use Math’s sqrt() method to calculate square root of number. Syntax [crayon-607c0eaccb66c665957671/] Return type It returns square root of the number. Square root of […]

- 07 September
### Power function in java

Power function in java is used to get first argument’s power to 2nd argument. For example: Let’s say you want to calculate 2 to the power 4. That will be 2*2*2*2=16 In java, you can do it by : Math.pow(2,4) =16 Syntax [crayon-607c0eaccbab0577497056/] Example : Let’s use power function in java. [crayon-607c0eaccbab5873755999/] When you run […]

- 02 September
### Java Math random example

In this post, we will see about Java math random example. Math’s random method provides you positive signed double value from 0.0 to 1.0. Syntax [crayon-607c0eaccbf18973086221/] This method can be used in multithreaded environment as it is thread safe. If you see the source code for random math, you will see that it uses java.util.Random […]

- 02 September
### Java Math floor example

Java math floor function is used to get largest integer which is lesser than number. Syntax [crayon-607c0eaccc341041900410/] Example Let’s use math’s floor function in the example. [crayon-607c0eaccc346737572177/] When you run above program, output of the program will be: Ceil value for 2.6 = 3.0 Ceil value for 26.1 = 27.0 Ceil value for -0.8 = […]