目录
方法---功能的最小单元

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);
}
}
注释
注释有三种形式:

java
/**
* 文档注释
*/
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工具插件。

小结
