Example
class MathJava {
public static void main(String[] args) {
// Declaring the variables
int num1 = -2;
float num2 = .8f;
// Printing the values
System.out.println("Initial value of int : "+num1);
System.out.println("Initial value of int : "+num2);
// Use of .abs() method to get the absoluteValue
int Absi = Math.abs(num1);
float Absf = Math.abs(num2);
System.out.println("Absolute value of int : "+Absi);
System.out.println("Absolute value of int : "+Absf);
System.out.println("");
// Use of acos() method Value greater than 1, so passing NaN
double Acosi = Math.acos(60);
System.out.println("acos value of Acosi : "+Acosi);
double x = Math.PI;
// Use of toRadian() method
x = Math.toRadians(x);
double Acosj = Math.acos(x);
System.out.println("acos value of Acosj : "+Acosj);
}
} |
class MathJava {
public static void main(String[] args) {
// Declaring the variables
int num1 = -2;
float num2 = .8f;
// Printing the values
System.out.println("Initial value of int : "+num1);
System.out.println("Initial value of int : "+num2);
// Use of .abs() method to get the absoluteValue
int Absi = Math.abs(num1);
float Absf = Math.abs(num2);
System.out.println("Absolute value of int : "+Absi);
System.out.println("Absolute value of int : "+Absf);
System.out.println("");
// Use of acos() method Value greater than 1, so passing NaN
double Acosi = Math.acos(60);
System.out.println("acos value of Acosi : "+Acosi);
double x = Math.PI;
// Use of toRadian() method
x = Math.toRadians(x);
double Acosj = Math.acos(x);
System.out.println("acos value of Acosj : "+Acosj); }
}
Output:
Initial value of int : -2
Initial value of int : 0.8
Absolute value of int : 2
Absolute value of int : 0.8
acos value of Acosi : NaN
acos value of Acosj : 1.5159376794536454 |
Initial value of int : -2
Initial value of int : 0.8
Absolute value of int : 2
Absolute value of int : 0.8 acos value of Acosi : NaN
acos value of Acosj : 1.5159376794536454