import java.io.*; /** * 这个类演示了文档注释 * @author Ayan Amhed * @version 1.2 */ publicclassSquareNum { /** * This method returns the square of num. * This is a multiline description. You can use * as many lines as you like. * @param num The value to be squared. * @return num squared. */ publicdoublesquare(double num) { return num * num; } /** * This method inputs a number from the user. * @return The value input as a double. * @exception IOException On input error. * @see IOException */ publicdoublegetNumber()throws IOException { InputStreamReaderisr=newInputStreamReader(System.in); BufferedReaderinData=newBufferedReader(isr); String str; str = inData.readLine(); return (newDouble(str)).doubleValue(); } /** * This method demonstrates square(). * @param args Unused. * @return Nothing. * @exception IOException On input error. * @see IOException */ publicstaticvoidmain(String args[])throws IOException { SquareNumob=newSquareNum(); double val; System.out.println("Enter value to be squared: "); val = ob.getNumber(); val = ob.square(val); System.out.println("Squared value is " + val); } }
C 语言
以 // 开始、以换行符结束的单行注释
constdouble pi = 3.1415926536; // pi是—个常量
以 / 开始、以 / 结束的块注释
intopen( constchar *name, int mode, … /* int permissions */ );