/********************
* SampleProgram
*
* reads user input with King's jpb package from the "Java Programming" book.
* See http://knking.com/books/java/jpb/index.html and pg 63 of the text.
*
*********************/
import jpb.*; // Define classes in jpb/
class SampleProgram {
public static void main(String args[]){ // main() method
SimpleIO.prompt(" Type in a number: "); // Ask user for input
String userInput = SimpleIO.readLine(); // Get the input as a string.
double x = Convert.toDouble(userInput); // Convert string to double.
double y = Math.sqrt(x); // Take square root.
System.out.println(" Its square root is " + y ); // Display result.
}
}
syntax highlighted by Code2HTML, v. 0.9.1