Java基础语法—最小单位、及注释

目录

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

注释

注释有三种形式:

小结


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

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工具插件。

小结

相关推荐
七老板的blog11 小时前
当 Spring StateMachine 遇见大模型:构建工业级 AI 写作流水线
java·人工智能·spring
小小编程路11 小时前
Python 还有容器类型互转、进制转换、字符编码转换
开发语言·windows·python
MartinYeung511 小时前
[论文学习]隐私保护联邦特徵选择与差分隐私的的工程实践框架
学习
想吃火锅100511 小时前
【leetcode】1.两数之和js版
javascript·算法·leetcode
qeen8712 小时前
【C++】类与对象之类的默认成员函数(二)
android·c语言·开发语言·c++·笔记·学习
云烟成雨TD12 小时前
Spring AI 1.x 系列【46】MCP Security 模块
java·人工智能·spring
CRMEB系统商城12 小时前
CRMEB多商户系统(Java)v2.3公测版发布
java·开发语言·人工智能·小程序·开源·php
sinat_2554878112 小时前
第七部分。介绍MVC(模型-视图-控制器)模式
java·ide·http·tomcat·intellij-idea
动能小子ohhh12 小时前
DocForge平台的设计与开发--文件上传接口的实现
开发语言·人工智能·python·langchain·ocr·fastapi