变量小练习和标识符

变量小练习和标识符

变量小练习

定义一个人类,用变量表示 姓名 性别 年龄 身高 体重

public class Demo08VarPerson{
    public static void main(string[] args){
        //姓名 
        String name = "张三";
        //性别 
        char sex = '男';
        //年龄 
        int arg = 20;
        //身高 
        double height = 172.5;
        //体重
        double weight = 140.9;
        
        System.out.println(name);
        System.out.println(sex);
        System.out.println(heigth);
        System.out.println(weigth);
    }
}

标识符

1.概述:咱们给类,方法,变量取的名字
2.注意:
    a.硬性规定(必须遵守)
      标识符可以包含"英文字母","数字","_"
      标识符不能以数字开头 int i1 = 100(正确) int 1i = 100(错误)
      标识符不能是关键字 int static = 100(错误)
    b.软性建议(建议遵守)
      给类取名字遵守大驼峰式-> 每个单词首字母大写
      给方法和变量取名字:遵循小驼峰->从第二个单词开始往后首字母大写
    见名知意
posted @ 2026-01-20 11:23  何小德  阅读(0)  评论(0)    收藏  举报