previous | start | next

File RootApproximatorTest2.java

1 import javax.swing.JOptionPane;
2
3 /**
4     This program computes square roots of user-supplied inputs.
5 */
6 public class RootApproximatorTest2
7 {  
8    public static void main(String[] args)
9    {  
10       boolean done = false;
11       while (!done)
12       {  
13          String input = JOptionPane.showInputDialog(
14             "Enter a number, Cancel to quit");
15
16          if (input == null) 
17             done = true;
18          else
19          {  
20             double x = Double.parseDouble(input);
21             RootApproximator r = new RootApproximator(x);
22             double y = r.getRoot();
23             
24             System.out.println("square root of " + x
25                + " = " + y);
26          }
27       }
28       System.exit(0);
29    }
30 }


previous | start | next