In this post, we will learn how to perform mathematical operations on numbers – power, squre root, floor, ceil, rounding numbers Here is the program that illustrates various mathematical operations in Java.
``````
package numbers;

/**
* Created by ssalunke on 14/04/2016.
*/
public class Maths {

public static void main(String [] args) throws Exception {

//Get absolute value
System.out.println("Absolute value of -2929.2 -> " + Math.abs(-2929.2));

//Rounding to 0 decimals
System.out.println("Round of the number -234.221 is ->" +
" " + Math.round(-234.221));

//Power method
System.out.println("2^3 is -> " +  Math.pow(2, 3));

//Finding square root
System.out.println("Square root of 525 -> " + Math.sqrt(525));

//Get random value
System.out.println("Random number -> " + String.valueOf(Math.random()));

}

}
``````
Here is the output of above example.
``````
Absolute value of -2929.2 -> 2929.2
Round of the number -234.221 is -> -234
2^3 is -> 8.0
Square root of 525 -> 22.9128784747792
Random number -> 0.6005728946831648
``````
Complex problems, Simple Solutions