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 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
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
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. Get Random Number between 0 and 1 in Java We can simply use Math.random() method to get random number between 0 to 1. Math.random method returns double value between […]
- 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-6729cea5bbd1a042935501/] 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-6729cea5bbeac047983006/] 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-6729cea5bc0be133205294/] Example : Let’s use power function in java. [crayon-6729cea5bc0c3434087415/] 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-6729cea5bc2d0130655884/] 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 ceil example
Java math ceil function is used to get smallest integer which is greater than number. Real life example Let’s say a telephone company charges you 1 dollar per minute. When you talk to someone for 1 minute 5 seconds, it will still charge you 2 dollar for that call. So telephone company can use Math.ceil […]