mukiibi 0 Newbie Poster

This code can help you to find the square root of three numbers accepting the inputs from the user and displaying the results in a Joption pane.
let me hope it will help

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Squareroot
{   
public static void main(String[] args)
{
String stringNum1,stringNum2,stringNum3;
double num1,num2,num3;
double root1,root2,root3;

DecimalFormat noDecimal = new DecimalFormat("0.#");
DecimalFormat twoDigits = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null, "The Program Below calculates the square root of 3 Numbers");
stringNum1 = JOptionPane.showInputDialog(null, "Enter First Number: ");
num1 = Double.parseDouble(stringNum1);
root1 = Math.sqrt(num1);

stringNum2 = JOptionPane.showInputDialog(null, "Enter Second number: ");
num2 = Double.parseDouble(stringNum2);
root2 = Math.sqrt(num2);

stringNum3 = JOptionPane.showInputDialog(null, "Enter Third number: ");
num3 = Double.parseDouble(stringNum3);
root3 = Math.sqrt(num3);

JOptionPane.showMessageDialog(null, "The square root of " +
noDecimal.format(num1) + " is " + twoDigits.format(root1)+"\nThe square root of " +
noDecimal.format(num2) + " is " + twoDigits.format(root2)+"\nThe square root of " +
noDecimal.format(num3) + " is " + twoDigits.format(root3));
   }
}