Compute Square Root of a Number in Java GUI
Submitted by donbermoy on Wednesday, May 14, 2014 - 09:41.
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
- import javax.swing.*;
- double squareRoot;
- String numInput;
- import javax.swing.*;
- public class sqrRoot {
- double squareRoot;
- String numInput;
- }
- }
Add new comment
- 920 views