变量与常量

it2023-11-10  66

变量与常量

public class Demo06 { public static void main(String[] args) { int a = 1; int b = 2; int c = 3; String name = “wuchentao”;//注意程序可读性 char x = ‘X’; double pi = 3.1415926; } } public class Demo07 { //类变量 static //属性;变量 //main方法 //实例变量;从属于对象,如果不进行初始化 则赋值为默认值 整型和浮点型为0 0.0 //布尔值默认为false //除了基本类型 其他都是null static double salary = 2500;//类变量 salary表示工资 String name; //实例变量 int age;

public static void main(String[] args) { //局部变量;必须声明和初始化值 int i = 10; System.out.println(i); //变量类型 变量名字 = new Demo08() Demo07 demo07 = new Demo07(); System.out.println(demo07.age); System.out.println(demo07.name); //类变量 static System.out.println(salary); } //其他方法 public void add(){ //add方法 }

} /***

░░░░░░░░░░░░░░░░░░░░░░░░▄░░░░░░░░░░░▐█░░░░░░░░░░░▄▀▒▌░░░░░░░░░▐▀▒█░░░░░░░░▄▀▒▒▒▐░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒单身狗就这样默默地看着你,一句话也不说。 */

public class Demo08 { //static final 修饰符 不存在先后顺序 final代表常量 //类变量加 static-静态的 static final double PI = 3.1415; final static double pi = 3.141; public static void main(String[] args) { System.out.println(PI); System.out.println(pi); /* 变量 方法 类名 ->见名知义 类成员 局部变量 方法名 :首字母小写 驼峰原则->除第一个单词 其他单词大写 lastName 常量 :大写字母加下划线-> PI_PDF 类名:首字母大写 驼峰原则->GoodGril */ } }

最新回复(0)