Java基础语法—最小单位、及注释
目录
方法—功能的最小单元
注释
注释有三种形式:
小结
方法—功能的最小单元
public class tast {public static void main(String[] args) {System.out.println(add(1, 2));System.out.println(factorial(5));}//计算两数之和方法public static int add(int a,int b){return a + b;}//计算5的阶乘方法public static int factorial(int n){if(n == 1){return 1;}return n * factorial(n - 1);}
}
注释
注释有三种形式:
/*** 文档注释*/
public class test {public static void main(String[] args) {//单行注释System.out.println("hello world");/*多行注释打印两个hello'= world*/System.out.println("hello world");System.out.println("hello world");}
}
如果别人的代码看不懂可以AI添加注释:这里需要看上一篇文件下载AI工具插件。