Math class Examples in Java Program


In Java Programming language Math class is in lang package which package by default attached in every  java program provided  by JVM (java virtual machine).

so we does not required import jav.lang package.

Math class provide mathemitacal inbuilt function  like absolute , ceil floor value,power value , sin ,cos  etc.


abs method of Math class in JAVA

absolute value means a value without sign

means return original value

if input value is negative  return positive value

if input value is positive  return  positive  value

 

Write a java program   print  absolute value of given value

output of abs method in Math class of lang package

absolute value in java program
absolute value in java program

 


pow method of Math class in JAVA

power value means base value multiply exponent times

i.e. 2 = 2*2*2  = 8 where 2 is base value and 3 is exponent

pow method return product of base value multiply exponent times

 

Write a java program   power of given  value  (i.e. 23 = 8) 

output of power method in Math class

power method in Math class
power method in Math class

 


ceil and  floor method of Math class in JAVA

ceil method return round up integer value

floor method return round down integer value

 

Write a java program  Find ceil and floor value  of given number using Math class.  

Output of ceil and floor  method in Math class

ceil & floor in java
ceil & floor in java
(Visited 55 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image