See below.
while
Loop Version
The first iteration of the loop body
can be made to happen by initializing
chars
to "yes."
This is slighly awkward.
import java.io.* ; class SqrtCalc { public static void main( String[] args ) throws IOException { String chars; double x; BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in) ); chars = "yes" ; // enable first iteration of the loop while ( chars.equals( "yes" ) ) { System.out.print("Enter a number-->"); chars = stdin.readLine(); x = Double.parseDouble( chars ); System.out.println("Square root of" + x + " is " + Math.sqrt( x ) ); System.out.print("Do you wish to continue? (yes or no) -->"); chars = stdin.readLine(); } } }