上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 23 下一页
摘要: 1.包装类是什么 基本数据类型变为引用数据类型,每一个都是一个类。 Integer age = new Integer(18); int age = 18; 2.为什么要用包装类 (1)使基本数据类型具有类的特点,创建对象,调用类的方法,符合面向对象。 (2)基本数据类型的默认值各不相同int的为0 阅读全文
posted @ 2022-09-19 18:30 植树chen 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 1.英寸和厘米换算 1英寸 = 2.54厘米 value = float(input("请输入长度:")) unit = input("请输入单位:") if unit == 'in' or unit == '英寸': print('%f英寸 = %f厘米' % (value, value * 2. 阅读全文
posted @ 2022-09-16 17:34 植树chen 阅读(980) 评论(0) 推荐(0) 编辑
摘要: 1.两个分支 if表达式和else后面要跟英文冒号,使用缩进的方式来表示层次结构,而不是花括号,通常为4个空格。 (1)判断闰年 year = int(input("请输入年份:")) if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 阅读全文
posted @ 2022-09-16 15:48 植树chen 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 1.华氏温度转换 从键盘输入华氏温度,将其转换为摄氏温度并输出。 公式:$C=(F - 32) \div 1.8$ C 表示摄氏温度,F 表示华氏温度 f = float(input("请输入华氏温度:")) c = (f-32)/1.8 #print(c) 37.77777777777778 pr 阅读全文
posted @ 2022-09-16 14:37 植树chen 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 1.赋值运算符 | 运算符 | 说明 | | | | | = | 赋值 | | += | a+=b 相当于 a = a+b | | = | a=b相当于a = a*b,a*=a+2相当于a=a*(a+2) | 2.比较运算符 | 运算符 | 说明 | | | | | == | 相等 | | != | 阅读全文
posted @ 2022-09-16 10:07 植树chen 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 1.变量类型转换 (1)int() | int() | 将一个数值或字符串转换成整数,可以指定进制 | | | | print(int(10+3)) #13 print(int("45")) #45 print(int('0011',2)) #3 将二进制数0011转化为十进制数3 print(in 阅读全文
posted @ 2022-09-15 19:40 植树chen 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 1.Object类中的equals()和toString() (1)Object类中定义的equals()和==的作用是相同的:比较两个对象的地址值是否相同,只能用于引用数据类型 public boolean equals(Object obj) { return (this == obj); } 阅读全文
posted @ 2022-09-15 17:08 植树chen 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 1.Object类源码 点击查看Object类源码-带注释 package java.lang; /** * Class {@code Object} is the root of the class hierarchy. * Every class has {@code Object} as a 阅读全文
posted @ 2022-09-15 16:39 植树chen 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 1.基本数据类型和引用数据类型转换比较 (1)基本数据类型转换 ① 自动类型转换:小->大 long g = 20; double d = 12.0f; ② 强制类型转换:大->小 float f = (float)12.0; int a = (int)1200L; (2)引用类型转换 ① 子类-> 阅读全文
posted @ 2022-09-15 08:56 植树chen 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 1.instanceof语法 x instanceof A:对象x是否是A类(或A类的子类)的对象,返回值为boolean类型。 A 也可为接口,x为A接口实现类对象。 x不是A类或A类的子类时,编译错误。 public void eat(Person person) { if (person in 阅读全文
posted @ 2022-09-14 19:37 植树chen 阅读(21) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 23 下一页