In java Math is a class, which is available in java.lang package. Math class contains many predefined methods we can use those methods to perform required mathematical operations.
The Math.max(x,y) method can be used to find the highest value of x and y:
public class Main {
public static void main(String[] args) {
int x = 5;
int y = 10;
System.out.println(Math.max(x, y);
}
}
The Math.min(x,y) method can be used to find the lowest value of x and y:
public class Main {
public static void main(String[] args) {
int x = 5;
int y = 10;
System.out.println(Math.min(x, y);
}
}
The Math.sqrt(x,y) method returns the square root of x:
public class Main {
public static void main(String[] args) {
int x = 5;
System.out.println(Math.sqrt(x);
}
}
The Math.abs(x) method returns the absolute (positive) value of x:
public class Main {
public static void main(String[] args) {
int x = -4.8;
System.out.println(Math.max(x);
}
}