bagwis
On-Chain Analyst
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial, you will learn how to compute a square root of a number using Java GUI using Math.sqrt function. We all know that square root are number that when multiplied by itself gives a given number.
Now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of sqrRoot.java.
2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the number.
3. Initialize your variable in your Main, variable numInput as string and make it as an input and variable squareRoot as double that will hold the output value of our output when we inputted on the inputBox.
4. Have now your computation on how to get the square root using Math.sqrt function. Put this code below.
5. Lastly, display the output of the program using JOptionPane.showMessageDialog.
Output:
Here's the full code of this tutorial:
Hope this helps! :)
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
Now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of sqrRoot.java.
2. Import javax.swing package. Hence we will use a GUI (Graphical User Interface) here like the inputting the number.
- import
javax.swing.*
;
3. Initialize your variable in your Main, variable numInput as string and make it as an input and variable squareRoot as double that will hold the output value of our output when we inputted on the inputBox.
- double
squareRoot;
- String
numInput;
- numInput =
JOptionPane
.showInputDialog
(
null
, "Enter a number:"
)
;
- squareRoot =
Double
.parseDouble
(
numInput)
;
4. Have now your computation on how to get the square root using Math.sqrt function. Put this code below.
- squareRoot =
Math
.sqrt
(
squareRoot)
;
5. Lastly, display the output of the program using JOptionPane.showMessageDialog.
- JOptionPane
.showMessageDialog
(
null
, "Square Root is: "
+
squareRoot)
;
Output:

Here's the full code of this tutorial:
- import
javax.swing.*
;
- public
class
sqrRoot {
- public
static
void
main(
String
[
]
args)
{
- double
squareRoot;
- String
numInput;
- numInput =
JOptionPane
.showInputDialog
(
null
, "Enter a number:"
)
;
- squareRoot =
Double
.parseDouble
(
numInput)
;
- squareRoot =
Math
.sqrt
(
squareRoot)
;
- JOptionPane
.showMessageDialog
(
null
, "Square Root is: "
+
squareRoot)
;
- }
- }
Hope this helps! :)
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
You must upgrade your account or reply in the thread to view hidden text.