The Math Class
Completed
Read two numbers x and y. Print Math.max, Math.pow(x, y), Math.sqrt(x) (3 decimals) and Math.abs(x - y).
Input
Two non-negative integers.
Output
Four lines.
Example
Input
2 10
Output
10 1024 1.414 8
Editor
Java
Hints
Math.pow returns a double; cast to long to print it without .0.
Solution explanation
Math holds static helper methods - you call them on the class, no object needed.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println(Math.max(x, y));
System.out.println((long) Math.pow(x, y));
System.out.printf("%.3f%n", Math.sqrt(x));
System.out.println(Math.abs(x - y));
}
}