Math 類別有 static sqrt() 方法 (method) ,回傳以第一個參數 (parameter) 的平方根
sqrt()
class SqrtDemo { public static void main(String[] args) { int i; for (i = 0; i <= 10; i++) { System.out.println(Math.sqrt(i)); } } }
0.0 1.0 1.4142135623730951 1.7320508075688772 2.0 2.23606797749979 2.449489742783178 2.6457513110645907 2.8284271247461903 3.0 3.1622776601683795
沒有留言:
張貼留言