Math Methods-Cube Root
Math Methods-Cube Root
Math.cbrt()
It is used to find the cube root of a positive or a negative
number. It always returns a value in double data type.
import java.lang.*;
public class CbrtExample1
{
public static void main(String[] args)
{
double x = 729;
//return the cube root of x
System.out.println(Math.cbrt(x));
}
}
Math Methods
Math Methods
Example
import java.lang.*;
public class CbrtExample2
{
public static void main(String[] args)
{
double x = 1.0/0;
// Input positive infinity, Output positive infinity
System.out.println(Math.cbrt(x));
}
}
Math Methods
Math Methods
Example
import java.lang.*;
public class CbrtExample3
{
public static void main(String[] args)
{
double x = -0.0;
// Input negative Zero, Output negative zero
System.out.println(Math.cbrt(x));
}
}
Math Methods
Math Methods
Math.log()
It is used to find the natural logarithmic value of a given
argument. It always returns a double type value.
public class LogExample1
{
public static void main(String[] args)
{
double x = 38.9;
// Input positive double, output logarithm of x
System.out.println(Math.log(x));
}
}
Math Methods
Math Methods
Math Methods
Example
public class LogExample2
{
public static void main(String[] args)
{
double x = 189.45;
// Input positive double, output logarithm of x
System.out.println(Math.log(x));
}
}
Math Methods
Math Methods
Math Methods
Example
public class LogExample2
{
public static void main(String[] args)
{
double x = -70.4;
// Input negative double, output NaN
System.out.println(Math.log(x));
}
}
Math Methods
Math Methods
Example
public class LogExample3
{
public static void main(String[] args)
{
double x = 1.0/0;
// Input positive infinity, output Infinity
System.out.println(Math.log(x));
}
}
Math Methods
Math Methods
Example
public class LogExample4
{
public static void main(String[] args)
{
double x = 0;
// Input positive zero, output -Infinity
System.out.println(Math.log(x));
}
}
Math Methods
Math Methods
Math.abs()
It always return the absolute value of an argument. The
return value may be int/long/double data type depending
upon the input arguments.
public class AbsExample1
{
public static void main(String args[])
{
int x = 78;
int y = -48;
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
Math Methods
Math Methods
Example
public class AbsExample2
{
public static void main(String args[])
{
double x = -47.63;
double y = -894.37;
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
System.out.println(Math.abs(7.0 / 0));
}
}
Math Methods
Math Methods
Example
public class AbsExample3
{
public static void main(String args[])
{
float x = -73.02f;
float y = -428.0f;
//print the absolute value of float type
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
}
}
Math Methods
Math Methods
Example
public class AbsExample4
{
public static void main(String args[])
{
long x = 78730343;
long y = -4839233;
System.out.println(Math.abs(x));
System.out.println(Math.abs(y));
System.out.println(Math.abs(Long.MIN_VALUE));
}
}
Math Methods