Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to calculate square root in Java

2 Answers

0 votes
class Program {
    public static void main(String[] args) {
        double d1 = 3.14;
        double d2 = 25;
 
        // double sqrt(double d)
        System.out.printf("sqrt(%.3f) is %.3f%n", d1, Math.sqrt(d1));
        System.out.printf("sqrt(%.3f) is %.3f%n", d2, Math.sqrt(d2));
    }
}



/*
run:

sqrt(3.140) is 1.772
sqrt(25.000) is 5.000

*/

 



answered Sep 8, 2016 by avibootz
edited May 20, 2024 by avibootz
0 votes
class Program {
    public static void main(String[] args) {
        double value = 121.0;
  
        System.out.format("The square root of %.2f is %.2f", value, Math.pow(value, 0.5));
    }
}



/*
run:

The square root of 121.00 is 11.00

*/

 



answered May 20, 2024 by avibootz
...