LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I Calculate Square and Square Root in Java? (https://www.linuxquestions.org/questions/programming-9/how-do-i-calculate-square-and-square-root-in-java-4175712791/)

coderromanholidaylog 05-30-2022 08:57 AM

How do I Calculate Square and Square Root in Java?
 
Wanted to understand how do I Calculate Square and Square Root in Java?

cinq 05-30-2022 10:37 AM

By using Java Math.sqrt

Example Code:

Code:

int X = 9;
double R = Math.sqrt(X);
System.out.println("The square root of " + X + " is " + R);

// The square root of 9 is 3.0

Read SQRT article on [link moderated]

astrogeek 05-30-2022 11:03 AM

The forum rules do not permit advertising. Please visit http://www.linuxquestions.org/advertising/ for more information on advertising. Feel free to contact the forum admin if you have any questions about this policy.

Pagonis 06-01-2022 03:19 PM

So a bot asked a question and bot answered by advertising. Interesting.

sundialsvcs 06-02-2022 07:06 AM

The "odd Use of capitalization" reveals This to Be a BOT. ... :)

dugan 06-02-2022 07:27 PM

Quote:

Originally Posted by Pagonis (Post 6358041)
So a bot asked a question and bot answered by advertising. Interesting.

That's super common.

frenchn00b 06-03-2022 09:41 AM

Quote:

Originally Posted by coderromanholidaylog (Post 6357521)
Wanted to understand how do I Calculate Square and Square Root in Java?

interesting question.

how to do that in C language ?

gcc or tcc or clang (C)

dugan 06-03-2022 12:57 PM

Assuming you’re serious:

Code:

#include <math.h>
#include <stdio.h>

int main()
{
    int n;
    n = 4;

    printf("Square: %d\n", n * n);
    printf("Square root: %f\n", sqrt(n));

    return 0;
}



All times are GMT -5. The time now is 12:03 PM.