/* * ============================================================================== * This Java program prompts a user for the radius of a circle, and then * computes and prints the circle area. * * Written By : Mark Austin July, 1997 * ============================================================================== */ import java.lang.Math; import java.util.*; import java.io.*; class Circle { public static void main( String args[] ) { float fRadius, fArea; String sLine; System.out.println("Area of Circle Program "); System.out.println("======================== "); System.out.println("Enter radius of circle : "); // Call keyboardInput() to read data from keyboard sLine = keyboardInput(); // Check input and convert returned string to a float if( sLine.length() > 0 ) { fRadius = Float.valueOf( sLine ).floatValue(); } else { System.out.println("ERROR >> You need to supply a floating point number"); return; } // Check that radius of circle is greater than zero if( fRadius <= 0 ) { System.out.println("ERROR >> Radius of circle must be greater than zero"); return; } // Compute Area of circle. fArea = ((float) Math.PI)*fRadius*fRadius; // Print radius and area of circle. System.out.println( "Radius of circle is : "+ fRadius ); System.out.println( "Area of cicle is : "+ fArea ); } // end main(). /* * ======================================================== * Method keyboardInput() : Get line of input from keyboard * ======================================================== */ static String keyboardInput() { String line; DataInputStream in = new DataInputStream(System.in); try{ line = in.readLine(); return line; } catch (Exception e){ return "error"; } } // end keyboardInput(). } // end class Circle.