1 import java.io.*; 2 3 /** 4 * 这个类演示了文档注释 5 * @author Mort 6 * @version 1.2 7 */ 8 public class SquareNum { 9 /** 10 * This method returns the square of num. 11 * This is a multiline description. You can use 12 * as many lines as you like. 13 * @param num The value to be squared. 14 * @return num squared. 15 */ 16 public double square(double num) { 17 return num * num; 18 } 19 /** 20 * This method inputs a number from the user. 21 * @return The value input as a double. 22 * @exception IOException On input error. 23 * @see IOException 24 */ 25 public double getNumber() throws IOException { 26 InputStreamReader isr = new InputStreamReader(System.in); 27 BufferedReader inData = new BufferedReader(isr); 28 String str; 29 str = inData.readLine(); 30 return (new Double(str)).doubleValue(); 31 } 32 /** 33 * This method demonstrates square(). 34 * @param args Unused. 35 * @return Nothing. 36 * @exception IOException On input error. 37 * @see IOException 38 */ 39 public static void main(String args[]) throws IOException 40 { 41 SquareNum ob = new SquareNum(); 42 double val; 43 System.out.println("Enter value to be squared: "); 44 val = ob.getNumber(); 45 val = ob.square(val); 46 System.out.println("Squared value is " + val); 47 } 48 }