Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Ex No.

14
Date:
Mathematical Functions
Aim:
To write a java program to perform mathematical operations.
Source Code:
import java.io.*;
public class mathclass{
public static void main(String[] args){
//E and round()
Double a = Math.E;
System.out.println("e = " + Math.round(a*100)/100f);
//PI
System.out.println("pi = " + Math.round(Math.PI*100)/100f);
//abs()
System.out.println("Absolute number = " + Math.abs(Math.PI));
//ceil()
System.out.println("Smallest integer value but greater than the
argument = " + Math.ceil(Math.PI));
//exp()
System.out.println("Exponent number powered by the argument = "
+ Math.exp(0));
//floor()
System.out.println("Largest integer value but less than the argu
ment = " + Math.floor(Math.E));
//IEEEremainder()
System.out.println("Remainder = " + Math.IEEEremainder(5.3f,2.2f
));
//max()
System.out.println("Maximum Number = " + Math.max(10,10.3));
//min()
System.out.println("Minimum Number = " + Math.min(10,10.3));
//pow()
System.out.println("Power = " + Math.pow(10,3));
//random()
System.out.println("Random Number = " + Math.random());
//rint()
System.out.println("Closest to the Argument = " + Math.rint(30))
;
//round()
System.out.println("Round = " + Math.round(Math.E));
//sqrt()
System.out.println("Square Root = " + Math.sqrt(400));
}
}
Output:
Javac mathclass.java
Java mathclass
e = 2.72
pi = 3.14
Absolute number = 3.141592653589793
Smallest integer value but greater than the argument = 4.0
Exponent number powered by the argument = 1.0
Largest integer value but less than the argument = 2.0
Remainder = 0.9000000953674316
Maximum Number = 10.3
Minimum Number = 10.0
Power = 1000.0
Random Number = 0.4821444718827098
Closest to the Argument = 30.0
Round = 3
Square Root = 20.0
Result:
Thus a java program has been written to perform the mathematical operati
ons.

You might also like