package Baozhuang; public class MathTest { public static void main(String[] args) { int m = 4; int n = 2; int max = Math.max(m, n); System.out.println(max);//最大值 int min = Math.min(m, n); System.out.println(min);//最小值 double pow = Math.pow(m, n); System.out.println(pow);//m的n次方 double sqrt = Math.sqrt(m); System.out.println(sqrt);//對m開平方 //random 隨機生成從0到10的隨機數,包括0 int random = (int) (Math.random()*10+1); System.out.println("生成隨機數"+random); //生成0或1的隨機數 int random1 = Math.random()*2 >= 0.5?1:0; System.out.println(random1); //生成5到10的隨機數 int random2 = (int)(Math.random()*6+5); System.out.println("5到10隨機數"+random2); //abs 求絕對值 int i = -6; int abs = Math.abs(i); System.out.println(abs); double angle = (Math.PI)/2; double sin = Math.sin(angle);//正旋 System.out.println(sin); double cos = Math.cos(angle);//餘旋 System.out.println(cos); double tan = Math.tan(angle); System.out.println(tan);//正切 double asin = Math.asin(angle); System.out.println(asin); double acos = Math.acos(asin); System.out.println(acos); } }