Pageviews

Friday 7 June 2013

Math functions in Java:

by Unknown  |  in Beginners at  Friday, June 07, 2013

Math functions are very important aspect for a program,especially when the Software depends upon the basic logics of Mathematics.In this post we are discussing various Math functions which are very simple to implement and is required in most of the programs,using these functions you need not to apply decision statements or conditions for checking the values,you can directly use the function and get value,the names of various math functions are:
  • Power
  • Square Root
  • Minimum,Maximum
  • Floor,Celing.

Here is the example of a simple program in which we had used all the functions as stated above:


Program to illustrate the use of Math functions in Java




class Port1{
public static void main(String args[]){
System.out.println(Math.sqrt(36));     //Square root takes just one argument
System.out.println(Math.pow(5,3));     //This takes power of 5 as 3 times 
System.out.println(Math.min(9,11));    //Minimum of 2 numbers
System.out.println(Math.max(7,9));     //Maximum of 2 numbers
System.out.println(Math.floor(9.9));    //This function will round off value below the given value
System.out.println(Math.ceil(9.1));     //This functions will round off the value above the given value
}



Math functions in Java



0 comments:

Proudly Powered by Blogger.