集册 Java实例教程 计算int值的平方根

计算int值的平方根

欢马劈雪     最近更新时间:2020-01-02 10:19:05

634
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
计算int值的平方根

public class Root {// from nowjava.com - 时  代  Java

    public static void main(String[] args) {

        int i = 2;

        double r = Math.sqrt(i);


        System.out.print("The square root of ");

        System.out.print(i);

        System.out.print(" is ");

        System.out.print(r);

        System.out.println(".");


        i = 5;

        r = Math.sqrt(i);

        System.out.println("The square root of " + i + " is " + r + ".");

    }

}


展开阅读全文