/* SquareRoot.java CIS 160 David G. Klick 2004-09-04 Demonstrates getting a square root with Math.sqrt() */ import java.text.DecimalFormat; public class SquareRoot { public static void main(String[] args) { DecimalFormat fourDec = new DecimalFormat("0.0000"); DecimalFormat noDec = new DecimalFormat("00"); for (double x=1.0; x<21.0; x+=1.0) { System.out.println("The square root of " + noDec.format(x) + " is " + fourDec.format(Math.sqrt(x))); } } } /* Sample output: The square root of 01 is 1.0000 The square root of 02 is 1.4142 The square root of 03 is 1.7321 The square root of 04 is 2.0000 The square root of 05 is 2.2361 The square root of 06 is 2.4495 The square root of 07 is 2.6458 The square root of 08 is 2.8284 The square root of 09 is 3.0000 The square root of 10 is 3.1623 The square root of 11 is 3.3166 The square root of 12 is 3.4641 The square root of 13 is 3.6056 The square root of 14 is 3.7417 The square root of 15 is 3.8730 The square root of 16 is 4.0000 The square root of 17 is 4.1231 The square root of 18 is 4.2426 The square root of 19 is 4.3589 The square root of 20 is 4.4721 */