LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-30-2022, 08:57 AM   #1
coderromanholidaylog
LQ Newbie
 
Registered: May 2022
Posts: 1

Rep: Reputation: 0
How do I Calculate Square and Square Root in Java?


Wanted to understand how do I Calculate Square and Square Root in Java?
 
Old 05-30-2022, 10:37 AM   #2
cinq
LQ Newbie
 
Registered: Apr 2022
Posts: 4

Rep: Reputation: 0
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]

Last edited by astrogeek; 05-30-2022 at 10:59 AM. Reason: Moderated ad link
 
Old 05-30-2022, 11:03 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
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.
 
Old 06-01-2022, 03:19 PM   #4
Pagonis
Member
 
Registered: Dec 2007
Location: Lithuania
Distribution: macOS on M1 Pro
Posts: 44

Rep: Reputation: 20
So a bot asked a question and bot answered by advertising. Interesting.
 
Old 06-02-2022, 07:06 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
The "odd Use of capitalization" reveals This to Be a BOT. ...
 
Old 06-02-2022, 07:27 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by Pagonis View Post
So a bot asked a question and bot answered by advertising. Interesting.
That's super common.
 
Old 06-03-2022, 09:41 AM   #7
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Quote:
Originally Posted by coderromanholidaylog View Post
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)
 
Old 06-03-2022, 12:57 PM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
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;
}

Last edited by dugan; 06-03-2022 at 02:03 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Circle square; How draw/compute w square pixels? Trigonometry, language rico001 Programming 6 04-27-2016 04:48 PM
[SOLVED] Sudoku - How to calculate the correct Box for a given Square? Jorek Programming 4 04-08-2011 03:02 PM
[SOLVED] in Fedora 11 square screen have not adjust square of monitor. us_ed Linux - Hardware 27 10-05-2010 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration