摘要: 有两种方法,递归和for循环 package com.hm.demo01; public class Test { public static void main(String[] args) { long result=func(10); System.out.println(result); } 阅读全文
posted @ 2022-03-27 13:55 SherryYuan 阅读(405) 评论(0) 推荐(0)
摘要: import java.util.Scanner; public class Test{ public static void main(String[] args){ Scanner scanner=new Scanner(System.in); …… double x=scanner.nextD 阅读全文
posted @ 2022-03-25 10:51 SherryYuan 阅读(154) 评论(0) 推荐(0)
摘要: 内存布局图👆 添加节点,有两种方式,第一种是直接添加到链表的尾部 第二种方式是插入到指定位置 第一种方式: 逻辑结构图👆 代码(实现水浒英雄排行榜管理,在添加英雄时,直接添加到链表的尾部) package com.demo02; public class SingleLinkedListTest 阅读全文
posted @ 2022-03-25 10:14 SherryYuan 阅读(163) 评论(0) 推荐(0)
摘要: 备注: 加数据是从队尾加,取数据是从队首取 front指向队列头部的前一个位置,初始值为-1 rear不是指向队列尾部的后一个位置,它是直接指向队列尾部的数据,初始值也是-1 将数据存入队列, 1)当front==rear,空 将尾指针往后移,rear++ 2)当rear==maxSize-1,队列 阅读全文
posted @ 2022-03-24 10:32 SherryYuan 阅读(73) 评论(0) 推荐(0)
摘要: final类 final方法 常量 package com.demo34; public class A { //若类被声明为final类,不可以被继承 final double PI=3.1415926; public double getArea(final double r) { //成员变量 阅读全文
posted @ 2022-03-24 09:27 SherryYuan 阅读(22) 评论(0) 推荐(0)
摘要: 内部类的分类:成员内部类(静态、非静态)vs局部内部类(方法内、代码块内、构造器内) 问题:一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 答案:可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致。一个文件中可以只有非public类,如果只 阅读全文
posted @ 2022-03-21 16:44 SherryYuan 阅读(6) 评论(0) 推荐(0)
摘要: 处理异常有两种方式: 一: package com.demo28; public class Test { public static void main(String[] args) { try { System.out.println(1/0); }catch(Exception e){ //e 阅读全文
posted @ 2022-03-20 22:43 SherryYuan 阅读(158) 评论(0) 推荐(0)
摘要: 成员变量有默认值,而局部变量是没有默认值的 package com.demo20; public class InitError { int x=10; int y; void f() { int m; x=y+m;////报错:The local variable m may not have b 阅读全文
posted @ 2022-03-18 16:47 SherryYuan 阅读(223) 评论(0) 推荐(0)
摘要: 含浮点数的计算 package com.demo19; public class Lader { float above; float bottom; float height; float area; float computerArea() { area=(above+bottom)*heigh 阅读全文
posted @ 2022-03-18 08:07 SherryYuan 阅读(25) 评论(0) 推荐(0)
摘要: (1)公共访问控制符 public:用 public 修饰的域称为公共域。由于 public 修饰符会降低运行的安全性和数据的封装性,所以一般应减少 public 域的使用。 (2)私有访问控制符 private:private 修饰的成员变量只能被该类自身所访问,不能被其它任何类 ( 包括子类 ) 阅读全文
posted @ 2022-03-17 19:22 SherryYuan 阅读(1086) 评论(0) 推荐(0)