Sunday, January 1, 2012

Perform 10 mathematical function in Java

Example



import java.io.*;
public class A16
{
public static void main(String args[])
throws IOException
{
double a,b;
BufferedReader br;
br=new BufferedReader(new InputStreamReader(System.in));
a=Double.parseDouble(br.readLine());
b=Double.parseDouble(br.readLine());
System.out.println("Maximum value is:"+Math.max(a,b));
System.out.println("Minimun value is:"+Math.min(a,b));
System.out.println("Floor of a and b is:"+Math.floor(a)+" "+Math.floor(b));
System.out.println("ceil of a and b is:"+Math.ceil(a)+" "+Math.ceil(b));
System.out.println("absolute of a and b is:"+Math.abs(a)+" "+Math.abs(b));
System.out.println("Nearest value of a and b is:"+Math.rint(a)+" "+Math.rint(b));
System.out.println("Rounded up value of a and  b is:"+Math.round(a)+ " "+Math.round(b));
System.out.println("In Radians :"+Math.toRadians(a)+"radians");
System.out.println("In Degree :"+Math.toDegrees(a)+"degree");
System.out.println("square root:"+Math.sqrt(a));
System.out.println("power of number:"+Math.pow(a,2));
}
}

No comments:

Post a Comment