Compare commits

...

42 Commits

Author SHA1 Message Date
6719f1e7b2 向数据库写入数据 2024-12-17 09:52:40 +08:00
a21a66a542 . 2024-12-16 12:33:30 +08:00
a3d1677a4c jdbc 2024-12-16 12:32:34 +08:00
4ba14576e7 读写文件文件 2024-12-11 14:09:38 +08:00
fdaf7334c8 文件基础操作 2024-12-10 10:39:13 +08:00
1de9754569 增加练习文件 2024-12-10 10:39:01 +08:00
2852b5f178 File基本操作 2024-12-09 08:57:54 +08:00
01d80d8ad2 利用TreeSet自动排序 2024-12-05 09:38:36 +08:00
c99f6f67b2 style 2024-12-05 08:54:54 +08:00
8aa6947e2b 案例6-4斗地主洗牌发牌 2024-12-03 10:27:20 +08:00
26fcbfbd91 泛型类、泛型方法、泛型接口 2024-12-01 22:42:52 +08:00
e4d146365b java.util.Properties 2024-12-01 22:36:34 +08:00
4d9579e13d HashMap和TreeMap 2024-12-01 22:36:24 +08:00
5a4df5e6f3 HashSet和TreeSet 2024-12-01 22:36:03 +08:00
d1ec1423dd . 2024-11-25 12:35:57 +08:00
c2923336e6 案例6-2学生管理系统 2024-11-24 20:28:33 +08:00
9e780a4f1b 迭代器遍历 2024-11-21 09:37:37 +08:00
f3cb1fe50d foreach循环 2024-11-21 09:37:36 +08:00
0d57276315 迭代器删除 2024-11-21 09:37:36 +08:00
c21520d8ee 案例6-1 库存管理系统 2024-11-21 09:35:47 +08:00
c0479e5bba ArrayList,LinkedList 2024-11-18 22:39:34 +08:00
6da1f053fb Duration和Period 2024-11-18 10:32:03 +08:00
c977d365d8 二月天 2024-11-18 10:31:46 +08:00
c26c27561c LocalDateTime 2024-11-13 21:51:35 +08:00
9c663672aa LocalDateTime 2024-11-13 21:51:19 +08:00
4d4a3beb6a LocalTime 2024-11-13 21:38:29 +08:00
78135ec799 LocalDate 2024-11-13 21:27:09 +08:00
ff273fbcde LocalDate 2024-11-12 09:41:23 +08:00
ce86998025 Math和Random 2024-11-12 09:41:16 +08:00
f80521d4a5 Runtime 2024-11-10 22:12:04 +08:00
a6c121d9a1 垃圾回收 2024-11-10 22:11:57 +08:00
886c549976 增加注释 2024-11-10 21:39:19 +08:00
730e6a8592 System.getProperties 2024-11-10 21:32:32 +08:00
fe9964116e System.currentTimeMillis() 2024-11-10 21:28:50 +08:00
57e12cb859 System.arraycopy 2024-11-10 21:23:39 +08:00
66c059eb0f 双十一购物车 2024-11-08 08:51:52 +08:00
00a5c68f22 对比String、StringBuilder、StringBuffer时间效率 2024-11-07 18:37:03 +08:00
8f3a52c938 案例6-1 模拟订单号生成 2024-11-07 18:36:45 +08:00
e645d37dad 双十一购物车 2024-11-07 18:36:18 +08:00
02bb45886d StringBuffer 类 2024-11-06 13:41:04 +08:00
a86d757053 无关紧要 2024-11-06 13:16:49 +08:00
58ad0dd15a 5.1 String类 2024-11-06 13:16:26 +08:00
92 changed files with 2806 additions and 5 deletions

View File

@@ -7,5 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

Binary file not shown.

2
note.txt Normal file
View File

@@ -0,0 +1,2 @@
这是第一行
这是第二行

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n

View File

@@ -0,0 +1 @@
public class GeneratedClass {\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n}\n

View File

@@ -0,0 +1 @@
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n}\n

View File

@@ -0,0 +1 @@
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n}\n

View File

@@ -0,0 +1 @@
public class GeneratedClass {\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n}\n

View File

@@ -0,0 +1 @@
Hello World! This is a random content. Always write clean and maintainable code. Documentation is very important for any project. Always write clean and maintainable code. Software development is both an art and science. The C programming language is powerful and efficient. Testing is an essential part of development. This file was automatically generated. Always write clean and maintainable code. Hello World! This is a random content. Remember to add proper comments in your code. Documentation is very important for any project. Hello World! This is a random content. The C programming language is powerful and efficient. Software development is both an art and science. Documentation is very important for any project. Always write clean and maintainable code. Documentation is very important for any project. Testing is an essential part of development. Documentation is very important for any project. Documentation is very important for any project. Java is a popular programming language. This is a sample text for testing purposes. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. This is a sample text for testing purposes. Testing is an essential part of development. The C programming language is powerful and efficient. Testing is an essential part of development. Testing is an essential part of development. Hello World! This is a random content. Always write clean and maintainable code. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Remember to add proper comments in your code. Testing is an essential part of development. Always write clean and maintainable code. Software development is both an art and science. This file was automatically generated. Testing is an essential part of development. Always write clean and maintainable code. Remember to add proper comments in your code. Java is a popular programming language. Java is a popular programming language. Documentation is very important for any project. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. The C programming language is powerful and efficient. This file was automatically generated. Hello World! This is a random content. Java is a popular programming language. Always write clean and maintainable code. This file was automatically generated. The C programming language is powerful and efficient. Testing is an essential part of development. This is a sample text for testing purposes. Hello World! This is a random content. Testing is an essential part of development. Always write clean and maintainable code. Java is a popular programming language. This is a sample text for testing purposes. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. This is a sample text for testing purposes. The C programming language is powerful and efficient. This is a sample text for testing purposes. Always write clean and maintainable code. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Remember to add proper comments in your code. Software development is both an art and science. Documentation is very important for any project. Testing is an essential part of development. This is a sample text for testing purposes. Testing is an essential part of development. Documentation is very important for any project. Java is a popular programming language. This file was automatically generated. Documentation is very important for any project. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. This is a sample text for testing purposes. Remember to add proper comments in your code. Documentation is very important for any project. Software development is both an art and science. This file was automatically generated.

View File

@@ -0,0 +1 @@
The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. This is a sample text for testing purposes. Hello World! This is a random content. Documentation is very important for any project. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Software development is both an art and science. Hello World! This is a random content. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. Software development is both an art and science. This is a sample text for testing purposes. Documentation is very important for any project. Java is a popular programming language. Software development is both an art and science. Software development is both an art and science. Java is a popular programming language. Always write clean and maintainable code. Hello World! This is a random content. Testing is an essential part of development. The C programming language is powerful and efficient. This file was automatically generated. Java is a popular programming language. This file was automatically generated. Testing is an essential part of development. Hello World! This is a random content. Hello World! This is a random content. Remember to add proper comments in your code. Testing is an essential part of development. The C programming language is powerful and efficient. Documentation is very important for any project. Documentation is very important for any project. The C programming language is powerful and efficient. This is a sample text for testing purposes. Documentation is very important for any project. Remember to add proper comments in your code. Java is a popular programming language. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. This file was automatically generated. Documentation is very important for any project. Remember to add proper comments in your code. Remember to add proper comments in your code. Remember to add proper comments in your code. Documentation is very important for any project. Remember to add proper comments in your code. Remember to add proper comments in your code. Always write clean and maintainable code. Java is a popular programming language. This file was automatically generated. This is a sample text for testing purposes. Software development is both an art and science. Hello World! This is a random content. Java is a popular programming language. Remember to add proper comments in your code. Documentation is very important for any project. Documentation is very important for any project. Always write clean and maintainable code. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Remember to add proper comments in your code. Testing is an essential part of development. The C programming language is powerful and efficient.

View File

@@ -0,0 +1 @@
Remember to add proper comments in your code. Documentation is very important for any project. Hello World! This is a random content. Java is a popular programming language. Always write clean and maintainable code. Java is a popular programming language. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. Remember to add proper comments in your code. The C programming language is powerful and efficient. Hello World! This is a random content. Documentation is very important for any project. This is a sample text for testing purposes. The C programming language is powerful and efficient. Java is a popular programming language. The C programming language is powerful and efficient. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Remember to add proper comments in your code. Testing is an essential part of development. Documentation is very important for any project. Java is a popular programming language. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. This file was automatically generated. This file was automatically generated. Always write clean and maintainable code. Software development is both an art and science. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. Testing is an essential part of development. The C programming language is powerful and efficient. Hello World! This is a random content. Remember to add proper comments in your code. Java is a popular programming language. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Software development is both an art and science. Always write clean and maintainable code. Hello World! This is a random content. Always write clean and maintainable code. Software development is both an art and science. Always write clean and maintainable code. Always write clean and maintainable code. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Remember to add proper comments in your code. Always write clean and maintainable code. Always write clean and maintainable code. This is a sample text for testing purposes. Always write clean and maintainable code. This file was automatically generated. Always write clean and maintainable code. Always write clean and maintainable code. Documentation is very important for any project. Testing is an essential part of development. Hello World! This is a random content. This file was automatically generated. Java is a popular programming language. Always write clean and maintainable code. Documentation is very important for any project. Java is a popular programming language. The C programming language is powerful and efficient. Hello World! This is a random content. Software development is both an art and science. Java is a popular programming language. Java is a popular programming language. This is a sample text for testing purposes. Software development is both an art and science. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. This is a sample text for testing purposes. Testing is an essential part of development. Documentation is very important for any project. Hello World! This is a random content. Documentation is very important for any project. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. This is a sample text for testing purposes. This is a sample text for testing purposes. Always write clean and maintainable code. Always write clean and maintainable code. Java is a popular programming language. Testing is an essential part of development. The C programming language is powerful and efficient. This is a sample text for testing purposes. The C programming language is powerful and efficient. Hello World! This is a random content. This is a sample text for testing purposes. Documentation is very important for any project. Software development is both an art and science. The C programming language is powerful and efficient. This file was automatically generated. Java is a popular programming language. Documentation is very important for any project. Remember to add proper comments in your code. This is a sample text for testing purposes. Testing is an essential part of development. Testing is an essential part of development.

View File

@@ -0,0 +1 @@
public class GeneratedClass {\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n}\n

View File

@@ -0,0 +1 @@
public class GeneratedClass {\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n}\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\n

View File

@@ -0,0 +1 @@
This file was automatically generated. This file was automatically generated. Remember to add proper comments in your code. Software development is both an art and science. The C programming language is powerful and efficient. Testing is an essential part of development. Java is a popular programming language. Hello World! This is a random content. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Testing is an essential part of development. This is a sample text for testing purposes. Documentation is very important for any project. Documentation is very important for any project. Testing is an essential part of development. Java is a popular programming language. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. Always write clean and maintainable code. The C programming language is powerful and efficient. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. This file was automatically generated. This file was automatically generated. Java is a popular programming language. Always write clean and maintainable code. Testing is an essential part of development. The C programming language is powerful and efficient. Java is a popular programming language. Always write clean and maintainable code. Testing is an essential part of development. Documentation is very important for any project. Software development is both an art and science. This is a sample text for testing purposes. This file was automatically generated. The C programming language is powerful and efficient. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Remember to add proper comments in your code.

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n

View File

@@ -0,0 +1 @@
This file was automatically generated. This is a sample text for testing purposes. Remember to add proper comments in your code. This is a sample text for testing purposes. Always write clean and maintainable code. This is a sample text for testing purposes. Software development is both an art and science. This file was automatically generated. Testing is an essential part of development. Java is a popular programming language. This file was automatically generated. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Always write clean and maintainable code. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. Testing is an essential part of development. Always write clean and maintainable code. The C programming language is powerful and efficient. Always write clean and maintainable code. This is a sample text for testing purposes. Always write clean and maintainable code. Java is a popular programming language. Remember to add proper comments in your code. Remember to add proper comments in your code. Software development is both an art and science. This file was automatically generated. Documentation is very important for any project. The C programming language is powerful and efficient. Hello World! This is a random content. Software development is both an art and science. Documentation is very important for any project. Always write clean and maintainable code. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. Testing is an essential part of development. Java is a popular programming language. Remember to add proper comments in your code. The C programming language is powerful and efficient. Testing is an essential part of development. This is a sample text for testing purposes. Testing is an essential part of development. Hello World! This is a random content. Documentation is very important for any project. Documentation is very important for any project. The C programming language is powerful and efficient. The C programming language is powerful and efficient. This file was automatically generated. Hello World! This is a random content. Documentation is very important for any project. Software development is both an art and science. Remember to add proper comments in your code. Software development is both an art and science. This is a sample text for testing purposes. Remember to add proper comments in your code. Always write clean and maintainable code. Software development is both an art and science. Java is a popular programming language. Remember to add proper comments in your code. Remember to add proper comments in your code. This file was automatically generated. Java is a popular programming language. This is a sample text for testing purposes. Testing is an essential part of development. This file was automatically generated. Hello World! This is a random content. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. This file was automatically generated. This is a sample text for testing purposes. Always write clean and maintainable code. This file was automatically generated. This file was automatically generated. Hello World! This is a random content. Testing is an essential part of development. Software development is both an art and science. Always write clean and maintainable code. Remember to add proper comments in your code. Hello World! This is a random content. Hello World! This is a random content. Software development is both an art and science. Hello World! This is a random content. Testing is an essential part of development. This is a sample text for testing purposes. Software development is both an art and science. Software development is both an art and science. Remember to add proper comments in your code. Hello World! This is a random content. Always write clean and maintainable code. Testing is an essential part of development. Java is a popular programming language. The C programming language is powerful and efficient. Documentation is very important for any project. Hello World! This is a random content. This file was automatically generated. Software development is both an art and science. Always write clean and maintainable code. The C programming language is powerful and efficient. The C programming language is powerful and efficient. Testing is an essential part of development. Hello World! This is a random content. Java is a popular programming language. Software development is both an art and science. Testing is an essential part of development. Remember to add proper comments in your code. The C programming language is powerful and efficient. Java is a popular programming language. Testing is an essential part of development.

View File

@@ -0,0 +1 @@
This file was automatically generated. Remember to add proper comments in your code. Hello World! This is a random content. Remember to add proper comments in your code. Remember to add proper comments in your code. This is a sample text for testing purposes. Hello World! This is a random content. Testing is an essential part of development. Always write clean and maintainable code. Testing is an essential part of development. Java is a popular programming language. This is a sample text for testing purposes. This file was automatically generated. The C programming language is powerful and efficient. Software development is both an art and science. This is a sample text for testing purposes. This is a sample text for testing purposes. Always write clean and maintainable code. Testing is an essential part of development. This is a sample text for testing purposes. Always write clean and maintainable code. The C programming language is powerful and efficient. Remember to add proper comments in your code. Java is a popular programming language. Hello World! This is a random content. This file was automatically generated. Always write clean and maintainable code. Always write clean and maintainable code. Documentation is very important for any project. This file was automatically generated. The C programming language is powerful and efficient. Software development is both an art and science. Testing is an essential part of development. Always write clean and maintainable code. Hello World! This is a random content. The C programming language is powerful and efficient. Always write clean and maintainable code. Software development is both an art and science. Remember to add proper comments in your code. Remember to add proper comments in your code. Hello World! This is a random content. Testing is an essential part of development. Documentation is very important for any project. Testing is an essential part of development. Always write clean and maintainable code. This is a sample text for testing purposes. This is a sample text for testing purposes. Software development is both an art and science. Documentation is very important for any project. Software development is both an art and science. Java is a popular programming language. Always write clean and maintainable code. The C programming language is powerful and efficient. This is a sample text for testing purposes.

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\n

View File

@@ -0,0 +1 @@
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\nvoid processData(int[] data) {\n for(int i = 0; i < data.length; i++) {\n data[i] = transform(data[i]);\n }\n}\n\npublic interface DataProcessor {\n void process(Data data);\n Result getResult();\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\nprivate static void logger(String message) {\n System.out.println("[LOG] " + message);\n}\n\npublic class Example {\n private String value;\n\n public Example(String value) {\n this.value = value;\n }\n\n public String getValue() {\n return value;\n }\n}\n\n

View File

@@ -0,0 +1,46 @@
package chapter10;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class Example01 {
public static void main(String[] args) {
try {
// 1. 加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// 2. 准备连接参数
String url = "jdbc:mysql://localhost:3306/school?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
String username = "root";
String password = "root";
// 使用try-with-resources自动关闭资源
try (
// 创建连接
Connection connection = DriverManager.getConnection(url, username, password);
// 创建语句对象
Statement statement = connection.createStatement();
// 执行查询获取结果集
ResultSet resultSet = statement.executeQuery("select * from student")
) {
// 处理结果集
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
String gender = resultSet.getString("gender");
String className = resultSet.getString("class");
System.out.println("id=" + id + ", name=" + name + ", age=" + age +
", gender=" + gender + ", className=" + className);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,37 @@
package chapter10;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
public class Example02 {
public static void main(String[] args) {
try {
// 1. 加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// 2. 准备连接参数
String url = "jdbc:mysql://localhost:3306/school?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
String username = "root";
String password = "root";
// 使用try-with-resources自动关闭资源
try (
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement()
) {
// 准备INSERT语句
String sql = "INSERT INTO student (name, age, gender, class, score) " +
"VALUES ('小张', 19, 'M', '计算机1班', 88.5)";
// 执行INSERT语句
int rows = statement.executeUpdate(sql);
// 输出受影响的行数
System.out.println("成功插入 " + rows + " 条数据");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,4 +1,14 @@
package chapter4;
public class Examaple25 {
public class Example25 {
public static void main(String[] args) {
int result = divide(4, 0);
System.out.println("结果:" + result);
System.out.println("程序继续运行...");
}
public static int divide(int x, int y) {
return x / y;
}
}

View File

@@ -1,2 +1,36 @@
package chapter4.example14;public class Example14 {
package chapter4.example14;
abstract class Animal {
abstract void shout();
}
class Cat extends Animal {
public void shout() {
System.out.println("喵喵...");
}
}
class Dog extends Animal {
public void shout() {
System.out.println("汪汪...");
}
}
class Example14 {
public static void main(String[] args) {
Animal cat = new Cat();
Animal dog = new Dog();
cat.shout();
dog.shout();
}
}
class Example15 {
public static void main(String[] args) {
Dog dog = new Dog();
Animal an = dog;
an.shout();
}
}

View File

@@ -1,5 +1,7 @@
package chapter4.object;
import java.util.HashSet;
class Student {
private String name;
private int age;
@@ -9,11 +11,17 @@ class Student {
this.age = age;
}
public String toString() {
return "Student {name=" + name + ", age=" + age + "}";
}
// public String toString() {
// return "Student {name=" + name + ", age=" + age + "}";
// }
}
public class Test {
public static void main(String[] args) {
Student s1 = new Student("张三", 23);
System.out.println(s1);
}
}

View File

@@ -0,0 +1,21 @@
package chapter5;
public class Example01 {
public static void main(String[] args) {
// 1、创建一个空的字符串
String str1 = new String();
// 2、创建一个内容为abcd的字符串
String str2 = new String("abcd");
// 3、创建一个内容为字符数组的字符串
char[] charArray = new char[]{'D', 'E', 'F'};
String str3 = new String(charArray);
// 4、创建一个内容为字节数组的字符串
byte[] arr = {97, 98, 99};
String str4 = new String(arr);
System.out.println("a" + str1 + "b");
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
}
}

View File

@@ -0,0 +1,13 @@
package chapter5;
public class Example02 {
public static void main(String[] args) {
String s = "abcdabc";
System.out.println("字符串的长度为:" + s.length());
System.out.println("字符串中第一个字符:" + s.charAt(0));
System.out.println("字符c第一次出现的位置:" + s.indexOf('c'));
System.out.println("字符c最后一次出现的位置:" + s.lastIndexOf('c'));
System.out.println("子字符串ab第一次出现的位置" + s.indexOf("ab"));
System.out.println("子字符串ab字符串最后一次出现的位置" + s.lastIndexOf("ab"));
}
}

View File

@@ -0,0 +1,24 @@
package chapter5;
public class Example03 {
public static void main(String[] args) {
String str = "abcdEFG";
// 1、转换成字符数组
System.out.print("将字符串转为字符数组后的结果:");
char[] charArray = str.toCharArray();
for (char c : charArray) {
System.out.print(c); // 打印当前遍历到的字符
System.out.print(','); // 每打印一个字符后,加一个逗号
}
// 2、把数字转换成字符串好用
System.out.println();
System.out.print("把数字123转换成字符串的效果");
System.out.println(String.valueOf(123));
// 3、大小写转换常用
System.out.println("转换成小写:" + str.toLowerCase());
System.out.println("转换成大写:" + str.toUpperCase());
}
}

View File

@@ -0,0 +1,16 @@
package chapter5;
public class Example04 {
public static void main(String[] args) {
String name = "王小明";
String newName = name.replace("", "");
System.out.println("旧名字:" + name + "\n新名字" + newName);
System.out.println();
String name2 = " 王 小明 ";
String name3 = name2.trim();
System.out.println("去除空格前:" + name2 + "\n去除空格后" + name3 );
// 思考:如何去掉所有空格?
}
}

View File

@@ -0,0 +1,14 @@
package chapter5;
public class Example05 {
public static void main(String[] args) {
String s1 = "我是王小明";
String s2 = "我是";
System.out.println("判断开头:" + s1.startsWith("我是"));
System.out.println("判断结尾:" + s1.endsWith("小明"));
System.out.println("判断包含:" + s1.contains(""));
System.out.println("判空:" + s1.isEmpty());
System.out.println("判断相等:" + s1.equals(s2));
}
}

View File

@@ -0,0 +1,16 @@
package chapter5;
public class Example06 {
public static void main(String[] args) {
String str = "石家庄-武汉-哈尔滨";
// 1、截取
System.out.println("从第5个字符截取到末尾" + str.substring(4));
System.out.println("从第5个字符截取到第6个字符" + str.substring(4, 6));
// 2、分割
System.out.println("分割后字符串数组中的元素依次是:");
String[] array = str.split("-");
for (String s : array) {
System.out.println(s);
}
}
}

View File

@@ -0,0 +1,48 @@
package chapter5;
public class Example08 {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
System.out.println("1、添加------------------------");
add(sb);
System.out.println("2、删除------------------------");
remove(sb);
System.out.println("3、修改------------------------");
alter();
}
public static void add(StringBuffer sb) {
sb.append("我王小明");
System.out.println("append添加结果" + sb);
sb.insert(1, "的名字是");
System.out.println("insert添加结果" + sb);
sb.append("");
System.out.println("append添加结果" + sb);
}
public static void alter() {
StringBuffer sb = new StringBuffer("我的性别是王小白");
sb.replace(2, 4, "姓名");
System.out.println("替换指定位置字符串:" + sb);
sb.setCharAt(0, '你');
System.out.println("修改指定位置字符:" + sb);
System.out.println("翻转:" + sb.reverse());
}
public static void remove(StringBuffer sb) {
sb.delete(0, 5);
System.out.println("delete的结果" + sb);
sb.deleteCharAt(3);
System.out.println("deleteCharAt结果" + sb);
sb.delete(0, sb.length());
System.out.println("清空:" + sb);
}
}

View File

@@ -0,0 +1,59 @@
package chapter5;
public class Example09 {
private static final int TIMES = 100000;
public static void main(String[] args) {
testString();
testStringBuffer();
testStringBuilder();
test();
}
// String时间效率
public static void testString() {
long start = System.currentTimeMillis();
String str = "";
for (int i = 0; i < TIMES; i++) {
str += "test";
}
long end = System.currentTimeMillis();
System.out.println("String测试耗时" + (end - start) + "ms");
}
// StringBuffer时间效率线程安全
public static void testStringBuffer() {
long start = System.currentTimeMillis();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < TIMES; i++) {
sb.append("test");
}
long end = System.currentTimeMillis();
System.out.println("StringBuffer测试耗时" + (end - start) + "ms");
}
// StringBuilder时间效率非线程安全
public static void testStringBuilder() {
long start = System.currentTimeMillis();
StringBuilder sb = new StringBuilder("hello");
for (int i = 0; i < TIMES; i++) {
sb.append("test");
}
long end = System.currentTimeMillis();
System.out.println("StringBuilder测试耗时" + (end - start) + "ms");
}
public static void test() {
String s1 = new String("abc");
String s2 = new String("abc");
System.out.println(s1.equals(s2)); // 打印结果为true
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.out.println(sb1.equals(sb2)); // 打印结果为false
StringBuilder sbr1=new StringBuilder("abc");
StringBuilder sbr2=new StringBuilder("abc");
System.out.println(sbr1.equals(sbr2)); // 打印结果为false
}
}

View File

@@ -0,0 +1,19 @@
package chapter5;
/**
* 拷贝数组
* System.arraycopy()
*/
public class Example10 {
public static void main(String[] args) {
int[] srcArray = {10 ,11, 12, 13, 14, 15, 16};
int[] toArray = {20, 21, 22, 23, 24, 25, 26, 27};
System.arraycopy(srcArray, 2, toArray, 3, 4);
System.out.println("拷贝后的数组元素为:");
for (int i = 0; i < toArray.length; i++) {
System.out.println("i : " + toArray[i]);
}
}
}

View File

@@ -0,0 +1,18 @@
package chapter5;
/**
* 获取当前时间
*/
public class Example11 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
String test = "";
for (int i = 0; i < 100000; i ++) {
test += "test";
}
long endTime = System.currentTimeMillis();
System.out.println("程序运行的时间:" + (endTime - startTime) + "ms");
}
}

View File

@@ -0,0 +1,21 @@
package chapter5;
import java.util.Enumeration;
import java.util.Properties;
/**
* 获取系统信息
*/
public class Example12 {
public static void main(String[] args) {
// 获取当前系统信息
Properties prop = System.getProperties();
Enumeration names = prop.propertyNames();
while (names.hasMoreElements()) {
String key = (String) names.nextElement();
String value = prop.getProperty(key);
System.out.println(key + "=" + value);
}
}
}

View File

@@ -0,0 +1,28 @@
package chapter5;
class Person implements AutoCloseable {
String name;
public Person(String name) {
this.name = name;
}
public void close() {
System.out.println( name + " 要被回收啦!");
}
}
public class Example13 {
public static void main(String[] args) {
Person p1 = new Person("小明");
Person p2 = new Person("大王");
p1 = null;
p2 = null;
System.gc();
for (int i = 0; i < 1000000; i ++) {
// 为了延长程序运行的时间
}
}
}

View File

@@ -0,0 +1,15 @@
package chapter5;
/**
* 获取当前虚拟机信息
*/
public class Example14 {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
System.out.println("处理器个数:" + rt.availableProcessors());
System.out.println("空闲内存:" + rt.freeMemory()/1024/1024 + "MB");
System.out.println("虚拟机中的内存总量:" + rt.totalMemory()/1024/1024 + "MB");
System.out.println("最大可用内存:" + rt.maxMemory()/1024/1024 + "MB");
}
}

View File

@@ -0,0 +1,15 @@
package chapter5;
public class Example16 {
public static void main(String[] args) {
System.out.println("计算绝对值的结果: " + Math.abs(-10));
System.out.println("求大于参数的最小整数: " + Math.ceil(5.6));
System.out.println("求小于参数的最大整数: " + Math.floor(-4.2));
System.out.println("对小数进行四舍五入后的结果: " + Math.round(-4.6));
System.out.println("求两个数的较大值: " + Math.max(2.1, -2.1));
System.out.println("求两个数的较小值: " + Math.min(2.1, -2.1));
System.out.println("生成一个大于等于0.0小于1.0随机值: " + Math.round(10 * Math.random()));
System.out.println("开平方的结果: "+Math.sqrt(4));
System.out.println("指数函数的值: "+Math.pow(2, 3));
}
}

View File

@@ -0,0 +1,13 @@
package chapter5;
import java.util.Random;
public class Example17 {
public static void main(String[] args) {
Random r = new Random(); // 不传入种子
for (int i = 0; i < 10; i++) {
// 随机产生10个[0,100)之间的整数
System.out.println(r.nextInt(100));
}
}
}

View File

@@ -0,0 +1,13 @@
package chapter5;
import java.util.Random;
public class Example18 {
public static void main(String[] args) {
Random r = new Random(13);
// 随机产生10个[0,100)之间的整数
for (int i = 0; i < 10; i++) {
System.out.println(r.nextInt(100));
}
}
}

View File

@@ -0,0 +1,12 @@
package chapter5;
import java.time.Instant;
public class Example20 {
public static void main(String[] args) {
Instant now = Instant.now();
System.out.println(now);
Instant instant = Instant.ofEpochMilli(1000 * 60 * 60 * 24);
System.out.println(instant);
}
}

View File

@@ -0,0 +1,33 @@
package chapter5;
import java.time.LocalDate;
public class Example21 {
public static void main(String[] args) {
LocalDate now = LocalDate.now();
LocalDate of = LocalDate.of(2015, 12, 12);
System.out.println("今年是" + now.getYear() + "");
System.out.println("月份:" + now.getMonth());
System.out.println("月份:" + now.getMonthValue());
System.out.println("日期:" + now.getDayOfMonth());
System.out.println("今年中的第几天:" + now.getDayOfYear());
System.out.println("周几:" + now.getDayOfWeek());
System.out.println("\n====判断相关的方法====");
System.out.println("of是否在now之前" + of.isBefore(now));
System.out.println("of是否在now之后" + of.isAfter(now));
System.out.println("of和now是否相等" + of.isEqual(now));
System.out.println("of是否闰年" + of.isLeapYear());
System.out.println("\n====解析和加减操作====");
String dateStr = "2020-02-12";
LocalDate date = LocalDate.parse(dateStr);
System.out.println("把字符串转换为日期对象:" + date);
System.out.println("年份加1:" + date.plusYears(1));
System.out.println("天数减5:" + date.minusDays(5));
System.out.println("指定年份为2024" + date.withYear(2024));
}
}

View File

@@ -0,0 +1,30 @@
package chapter5;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class Example22 {
public static void main(String[] args) {
// 1. 获取当前时间
LocalTime now = LocalTime.now();
// 2. 表示过去时间
LocalTime of = LocalTime.of(9, 23, 23);
// 3. 三个getter
System.out.println("时:" + now.getHour());
System.out.println("分:" + now.getMinute());
System.out.println("秒:" + now.getSecond());
// 4. 格式转换,借助 DateTimeFormatter
System.out.println("\nnow默认格式" + now);
System.out.println("不显示微秒:" + now.withNano(0));
System.out.println("转换格式:" + now.format(DateTimeFormatter.ofPattern("HH:mm:ss")));
System.out.println("转换格式:" + now.format(DateTimeFormatter.ofPattern("HH点mm分ss秒")));
// 5. 判断
System.out.println("\nof在now之前吗" + of.isBefore(now));
// 6. 解析字符串
LocalTime time = LocalTime.parse("12:15:30");
System.out.println("将字符串转换成时间对象:" + time);
}
}

View File

@@ -0,0 +1,19 @@
package chapter5;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Example23 {
public static void main(String[] args) {
// 1. 获取当前时间
LocalDateTime now = LocalDateTime.now();
System.out.println("原格式:" + now);
System.out.println("只有日期:" + now.toLocalDate());
System.out.println("只有时间:" + now.toLocalTime());
// 2. getter 方法
System.out.println(now.getYear() +"" + now.getMonthValue() + "" + now.getDayOfMonth() + ""
+ now.getHour() + "" + now.getMinute() + "" + now.getSecond() + "");
// 3. 指定格式
System.out.println("指定格式:" + now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
}

View File

@@ -0,0 +1,20 @@
package chapter5;
import java.time.Duration;
import java.time.LocalTime;
public class Example24 {
public static void main(String[] args) {
LocalTime start = LocalTime.now();
LocalTime end = LocalTime.of(21, 53, 0);
Duration duration = Duration.between(start, end);
System.out.println("时间间隔(纳秒)" + duration.toNanos());
System.out.println("时间间隔(毫秒)" + duration.toMillis());
System.out.println("时间间隔(秒)" + duration.toSeconds());
System.out.println("时间间隔(分钟)" + duration.toMinutes());
System.out.println("时间间隔(小时)" + duration.toHours());
}
}

View File

@@ -0,0 +1,16 @@
package chapter5;
import java.time.LocalDate;
import java.time.Period;
public class Example25 {
public static void main(String[] args) {
LocalDate birthday = LocalDate.of(2018, 12, 12);
LocalDate now = LocalDate.of(2020, 11, 13);
Period period = Period.between(birthday, now);
System.out.println("时间间隔(年)" + period.getYears());
System.out.println("时间间隔(月)" + period.getMonths());
System.out.println("时间间隔(天)" + period.getDays());
}
}

View File

@@ -0,0 +1,202 @@
package chapter5;
/**
* 双十一购物车
* 需求:
* 1. 添加商品到购物车商品名称用StringBuilder拼接
* 2. 显示购物车商品清单把StringBuilder转换为String输出
* 3. 修改商品名称用String的replace方法
* 4. 删除购物车某个商品用StringBuilder的delete方法
* 5. 计算购物车商品总价
*/
public class ShoppingCart {
private StringBuilder cart; // 购物车商品列表
private double totalPrice; // 总价格
/**
* 构造方法思路:
* 1. 创建空的购物车使用StringBuilder存储商品信息
* 2. 初始化总价为0
* 为什么使用StringBuilder因为购物车内容会经常变动StringBuilder更适合频繁修改
*/
public ShoppingCart() {
cart = new StringBuilder();
totalPrice = 0.0;
}
/**
* addItem方法思路
* 1. 判断购物车是否为空
* - 如果不空,需要先添加分隔符", "
* - 如果是空的,直接添加商品
* 2. 拼接商品信息:商品名(¥价格)
* 例如:小米手机(¥1999.0)
* 3. 更新总价
*
* 考虑为什么要加if判断
* - 为了避免第一个商品前也加逗号
* - 让商品列表更美观商品1(¥xx), 商品2(¥xx), 商品3(¥xx)
*/
public void addItem(String item, double price) {
if (!cart.isEmpty()) {
cart.append(", ");
}
cart.append(item).append("(¥").append(price).append(")");
totalPrice += price;
}
/**
* showCart方法思路
* 1. 先判断购物车是否为空
* - 如果为空,返回提示信息
* - 如果不为空,显示商品清单和总价
* 2. 把StringBuilder转换为String返回
*
* 为什么要转换成String
* - String更适合显示最终结果
* - println方法接收String类型参数
*/
public String showCart() {
if (cart.isEmpty()) {
return "购物车是空的呢,快去选购吧!";
}
return "购物车商品: " + cart.toString() + "\n总价: ¥" + totalPrice;
}
/**
* modifyItem方法思路
* 1. 先将StringBuilder转换为String
* 2. 使用String的replace方法替换商品名
* 3. 将修改后的String再转回StringBuilder
*
* 为什么要转换来转换去?
* - String的replace方法使用更方便
* - StringBuilder没有直接的替换方法
* 注意:这里没有修改价格,实际项目中可能需要考虑价格变化
*/
public void modifyItem(String oldItem, String newItem) {
String cartStr = cart.toString();
cartStr = cartStr.replace(oldItem, newItem);
cart = new StringBuilder(cartStr);
}
/**
* removeItem方法思路
* 1. 找到要删除商品名的起始位置indexOf
* 2. 如果找到了start != -1
* - 找到这个商品信息的结束位置(")"的位置再+1
* - 如果后面还有商品,则多删除", "这两个字符
* 3. 使用StringBuilder的delete方法删除
* 4. 更新总价
*
* 难点解析:
* end < cart.length() && cart.charAt(end) == ','
* - 为什么要判断end < cart.length()?避免数组越界
* - 为什么要判断逗号?确保后面还有其他商品
*/
public void removeItem(String item, double price) {
int start = cart.indexOf(item);
if (start != -1) {
int end = cart.indexOf(")", start) + 1;
if (end < cart.length() && cart.charAt(end) == ',') {
end += 2; // 删除后面的逗号和空格
}
cart.delete(start, end);
totalPrice -= price;
}
}
/**
* 清空购物车方法思路:
* 1. 使用StringBuilder的setLength(0)清空购物车内容
* - 比创建新对象更高效
* - 比delete(0,length)更简洁
* 2. 重置总价为0
*
* 为什么用setLength(0)而不是cart = new StringBuilder()?
* - setLength(0)只是将长度设为0原有空间仍可重用
* - 创建新对象会产生额外的内存开销
*/
public void clearCart() {
cart = new StringBuilder();
totalPrice = 0.0;
}
/**
* 对购物车中指定商品应用折扣
* 折扣范围: 0.0-1.0 (例如0.8表示8折)
* 实现思路:
* 1. 检查折扣是否合法
* 2. 在购物车中查找商品
* 3. 提取商品原价
* 4. 计算新价格并更新购物车
* 5. 更新总价
*
* @param item 要打折的商品名称
* @param discount 折扣率(0.0-1.0)
* @throws IllegalArgumentException 当折扣不在有效范围内时抛出
*/
public void applyDiscount(String item, double discount) {
// 验证折扣是否合法
if (discount <= 0.0 || discount >= 1.0) {
throw new IllegalArgumentException("折扣必须在0.0到1.0之间");
}
// 查找商品在购物车中的位置
String cartStr = cart.toString();
int itemStart = cartStr.indexOf(item);
if (itemStart == -1) {
return; // 商品不存在,直接返回
}
// 提取价格信息
int priceStart = cartStr.indexOf("", itemStart);
int priceEnd = cartStr.indexOf(")", priceStart);
double originalPrice = Double.parseDouble(cartStr.substring(priceStart + 1, priceEnd));
// 计算新价格
double newPrice = originalPrice * discount;
// 更新总价
totalPrice = totalPrice - originalPrice + newPrice;
// 更新购物车中的价格
String oldPriceStr = String.format("¥%.1f", originalPrice);
String newPriceStr = String.format("¥%.1f", newPrice);
cart.replace(priceStart, priceEnd, newPriceStr);
}
public static void main(String[] args) {
// 测试购物车
ShoppingCart cart = new ShoppingCart();
System.out.println(cart.showCart());
System.out.println();
// 添加商品
cart.addItem("小米手机", 1999.0);
cart.addItem("耳机", 299.0);
cart.addItem("充电器", 39.9);
System.out.println("添加商品后:");
System.out.println(cart.showCart());
// 修改商品名称
cart.modifyItem("小米手机", "华为手机");
System.out.println("\n修改商品后");
System.out.println(cart.showCart());
// 应用商品折扣
cart.applyDiscount("耳机", 0.8);
System.out.println("\n应用折扣后");
System.out.println(cart.showCart());
// 删除商品
cart.removeItem("耳机", 299.0);
System.out.println("\n删除商品后");
System.out.println(cart.showCart());
// 清空购物车
cart.clearCart();
System.out.println("\n清空购物车后");
System.out.println(cart.showCart());
}
}

View File

@@ -0,0 +1,47 @@
package chapter5.demo51;
public class OrderID {
public static void main(String[] args) {
System.out.println("====String实现====");
int[] time = {2024, 1107, 1040};
String orderID = arrayToString(time);
System.out.println("订单号 " + orderID);
System.out.println("\n====StringBuffer实现====");
int[] time2 = {2023, 1006, 1200};
String orderID2 = arrayToString(time2);
System.out.println("订单号 " + orderID2);
}
/**
* 将数组拼接成字符串,并在首尾添加`OID:[]`
* 注意使用String实现
* @param arr 存放数字的数组
* @return 拼接后的字符串,格式为`[202411071040]`
*/
public static String arrayToString(int[] arr) {
String s = "";
s += "OID:[";
for (int c : arr) {
s += c;
}
s += ']';
return s;
}
/**
* 将数组拼接成字符串,并在首尾添加`OID:[]`
* 注使用StringBuffer实现
* @param arr 存放数字的数组
* @return 拼接后的字符串,格式为`[202411071040]`
*/
public static String arrayToStringUsingBuffer(int[] arr) {
StringBuffer sb = new StringBuffer();
sb.append("OID:[");
for (int c : arr) {
sb.append(c);
}
sb.append("]");
return sb.toString();
}
}

43
src/chapter5/demo55.java Normal file
View File

@@ -0,0 +1,43 @@
package chapter5;
import java.time.LocalDate;
import java.util.Scanner;
public class demo55 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("请输入要判断的年份:");
int year = scn.nextInt();
System.out.println("方法一:" + year + "的2月有" + getNumOfDaysInFeb1(year) + "");
System.out.println("方法二:" + year + "的2月有" + getNumOfDaysInFeb2(year) + "");
}
/**
* 思路一
* @param year 年份
* @return 2月的天数
*/
public static int getNumOfDaysInFeb1(int year) {
LocalDate date = LocalDate.of(year, 3, 1);
LocalDate feb = date.minusDays(1);
return feb.getDayOfMonth();
}
/**
* 思路二
* @param year 年份
* @return 2月的天数
*/
public static int getNumOfDaysInFeb2(int year) {
LocalDate date = LocalDate.of(year, 1, 1);
if (date.isLeapYear()) {
return 29;
} else {
return 28;
}
// return date.isLeapYear() ? 29 : 28;
}
}

View File

@@ -0,0 +1,38 @@
package chapter6;
import java.util.ArrayList;
public class Example01 {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add("张三");
list.add("李四");
list.add("王五");
list.add("赵六");
list.add("钱七");
list.add("孙八");
// 获取集合中元素的个数
System.out.println("元素个数:" + list.size());
// 取出指定位置的元素
System.out.println("第2个元素" + list.get(1));
// 取出所有元素
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + "\t");
}
System.out.println();
// 删除第2个元素
list.remove(1);
// 取出所有元素
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + "\t");
}
// 计算位置
System.out.println("\n赵六是第" + list.indexOf("赵六"));
// 直接打印所有元素,不用手动遍历
System.out.println(list.toString());
}
}

View File

@@ -0,0 +1,24 @@
package chapter6;
import java.util.LinkedList;
public class Example02 {
public static void main(String[] args) {
LinkedList link = new LinkedList();
link.add("张三");
link.add("李四");
link.add("王五");
link.add("赵六");
link.add("钱七");
link.add("孙八");
System.out.println(link.toString()); // 取出并打印该集合中的元素
link.add(3, "Student"); // 向该集合中指定位置插入元素
link.addFirst("First"); // 向该集合第一个位置插入元素
System.out.println(link);
System.out.println(link.getFirst()); // 取出该集合中第一个元素
link.remove(3); // 移除该集合中指定位置的元素
link.removeFirst(); // 移除该集合中第一个元素
System.out.println(link);
}
}

View File

@@ -0,0 +1,24 @@
package chapter6;
import java.util.ArrayList;
import java.util.Iterator;
public class Example04 {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("张三");
list.add("李四");
list.add("王五");
list.add("张三");
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String name = iterator.next();
if (name.equals("张三")) {
iterator.remove();
}
}
System.out.println(list);
}
}

View File

@@ -0,0 +1,17 @@
package chapter6;
import java.util.ArrayList;
public class Example05 {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
for(String s : list){
System.out.println(s);
}
}
}

View File

@@ -0,0 +1,73 @@
package chapter6;
import java.util.HashSet;
import java.util.Iterator;
class Student implements Comparable<Student> {
String id;
String name;
int height;
public Student(String id, String name) {
this.id = id;
this.name = name;
}
public void setHeight(int height) {
this.height = height;
}
public String toString() {
return id + ":" + name;
}
public int hashCode() {
return id.hashCode();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Student)) {
return false;
}
Student other = (Student) obj;
return this.id.equals(other.id);
}
public int compareTo(Student other) {
if (this.height > other.height) {
return 1; // 返回正数:表示"我"比"你"大
} else if (this.height < other.height) {
return -1; // 返回负数:表示"我"比"你"小
} else {
return 0; // 返回0表示"我"和"你"一样大
}
}
}
public class Example08 {
public static void main(String[] args) {
HashSet<Student> students = new HashSet<>();
Student s1 = new Student("1", "张三");
Student s2 = new Student("2", "李四");
Student s3 = new Student("2", "李四");
Student s4 = new Student("3", "王五");
students.add(s3);
students.add(s4);
students.add(s1);
students.add(s2);
Iterator<Student> iterator = students.iterator();
while (iterator.hasNext()) {
Student student = iterator.next();
System.out.println(student);
}
}
}

View File

@@ -0,0 +1,21 @@
package chapter6;
import java.util.TreeSet;
public class Example12 {
public static void main(String[] args) {
Student s1 = new Student("1", "张三");
s1.setHeight(175);
Student s2 = new Student("2", "李四");
s2.setHeight(170);
Student s4 = new Student("3", "王五");
s4.setHeight(180);
TreeSet<Student> students = new TreeSet<>();
students.add(s1);
students.add(s2);
students.add(s4);
System.out.println(students);
}
}

View File

@@ -0,0 +1,27 @@
package chapter6;
import java.util.HashMap;
public class Example14 {
public static void main(String[] args) {
HashMap map = new HashMap(); // 创建Map对象
map.put("1","张三");//存储键和值
map.put("2","李四");
map.put("3","王五");
map.put("3", "赵六");
System.out.println("1" + map.get("1")); // 根据键获取值
System.out.println("2: " + map.get("2"));
System.out.println("3: " + map.get("3"));
System.out.println("键值对数量:" + map.size());
// if (map.containsKey("1")) {
// System.out.println("1号存在");
// }
//
// if (map.containsValue("李四")) {
// System.out.println("李四存在");
// }
}
}

View File

@@ -0,0 +1,52 @@
package chapter6;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Example15 {
public static void main(String[] args) {
HashMap map = new HashMap(); // 创建Map对象
map.put("2","李四"); //存储键和值
map.put("3","王五");
map.put("1","张三");
// 方法一
Set keySet = map.keySet(); //获取键的集合
Iterator it = keySet.iterator();//选代键的集合
while (it.hasNext()) {
Object key = it.next();
Object value = map.get(key); //获取每个键所对应的值
System.out.println(key + ":" + value);
}
Iterator it2 = map.keySet().iterator();
while (it2.hasNext()) {
Object key = it2.next();
System.out.println(key);
}
Iterator it3 = map.values().iterator();
while (it3.hasNext()) {
Object value = it3.next();
System.out.println(value);
}
// 方法二
Set entrySet = map.entrySet(); // 获取所有映射关系
Iterator it4 = entrySet.iterator(); // 获取Iterator对象
while (it4.hasNext()){
//获取集合中键值对映射关系
Map.Entry entry = (Map.Entry) (it4.next());
Object key = entry.getKey();//获取Entry中的键
Object value = entry.getValue();//获取Entry中的值
System.out.println(key + ":" + value);
}
for (Object obj : map.entrySet()) {
System.out.println(obj);
}
}
}

View File

@@ -0,0 +1,23 @@
package chapter6;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;
public class Example19 {
public static void main(String[] args) {
TreeMap map = new TreeMap(); // 创建Map集合
map.put(3, "李四"); // 存储键和值
map.put(2, "王五");
map.put(4, "赵六");
map.put(3, "张三");
Set keySet = map.keySet();
Iterator iterator = keySet.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Object value = map.get(key);
System.out.println(key + ":" + value);
}
}
}

View File

@@ -0,0 +1,20 @@
package chapter6;
import java.util.Enumeration;
import java.util.Properties;
public class Example21 {
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty("Backgroudnd", "red");
p.setProperty("Font-size", "14px");
p.setProperty("Language", "Chinese");
Enumeration names = p.propertyNames();
while (names.hasMoreElements()) {
String key = (String) names.nextElement();
String value = p.getProperty(key);
System.out.println(key + "=" + value);
}
}
}

View File

@@ -0,0 +1,33 @@
package chapter6;
// T 标识一个不确定的类型
class Score<T> {
private String studentName; // 学生姓名
private String subject; // 课程名称
private T value; // 成绩值(可以是任意类型)
// 构造方法
public Score(String studentName, String subject, T value) {
this.studentName = studentName;
this.subject = subject;
this.value = value;
}
public String toString() {
return studentName + "" + subject + "成绩是" + value;
}
}
public class Example22 {
public static void main(String[] args) {
// 创建三个成绩对象,分别存储小明的数学、英语、军事理论成绩
Score<Integer> s1 = new Score<Integer>("小明", "数学", 100);
Score<String> s2 = new Score<String>("小明", "英语", "A");
Score<String> s3 = new Score<String>("小明", "军事理论", "合格");
// 打印三门课程的成绩
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
}

View File

@@ -0,0 +1,29 @@
package chapter6;
import java.util.ArrayList;
import java.util.Iterator;
public class Example23 {
public static void main(String[] args) {
// 存放字符串的集合
ArrayList<String> names = new ArrayList<String>();
names.add("张三"); // √ 正确
Iterator it1 = names.iterator();
while (it1.hasNext()) {
String name = (String) it1.next();
System.out.println(name);
}
ArrayList students = new ArrayList();
names.add("张三");
Iterator it2 = students.iterator();
while (it2.hasNext()) {
String student = (String) it2.next();
System.out.println(student);
}
}
}

View File

@@ -0,0 +1,36 @@
package chapter6;
public class Example24 {
// 泛型方法:验证订单信息
public static <T> boolean verify(T info) {
System.out.println("正在验证: " + info);
if (info instanceof String) {
// 验证订单号
String orderNo = (String) info;
return orderNo.length() == 10; // 假设订单号必须是10位
}
else if (info instanceof Double || info instanceof Integer) {
// 验证订单金额
double amount = Double.parseDouble(info.toString());
return amount > 0; // 金额必须大于0
}
return false;
}
public static void main(String[] args) {
// 验证订单号
boolean isValidOrderNo = verify("A123456789");
System.out.println("订单号是否合法: " + isValidOrderNo);
// 验证订单金额
boolean isValidAmount = verify(99.9);
System.out.println("订单金额是否合法: " + isValidAmount);
// 验证负数金额
boolean isValidNegative = verify(-10.0);
System.out.println("负数金额是否合法: " + isValidNegative);
}
}

View File

@@ -0,0 +1,59 @@
package chapter6;
// 定义支付接口(泛型接口)
interface Payment<T> {
boolean pay(T amount); // 支付方法
T getBalance(); // 获取余额
}
// 方式一:明确类型的接口实现 - 支付宝支付
class AliPay implements Payment<Double> {
private Double balance = 1000.0;
@Override
public boolean pay(Double amount) {
if (balance >= amount) {
balance -= amount;
System.out.println("支付成功:" + amount + "");
return true;
}
return false;
}
@Override
public Double getBalance() {
return balance;
}
}
// 方式二:泛型类型的接口实现 - 校园卡支付
class CampusCard<T> implements Payment<T> {
private T balance;
public CampusCard(T balance) {
this.balance = balance;
}
@Override
public boolean pay(T amount) {
System.out.println("支付积分:" + amount);
return true;
}
@Override
public T getBalance() {
return balance;
}
}
public class Example25 {
public static void main(String[] args) {
// 测试支付宝支付
AliPay aliPay = new AliPay();
aliPay.pay(100.0);
// 测试校园卡支付
CampusCard<Integer> campusCard = new CampusCard<>(500);
campusCard.pay(100);
}
}

View File

@@ -0,0 +1,22 @@
package chapter6;
import java.util.ArrayList;
import java.util.Iterator;
public class Example3 {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
Iterator<String> iterator = list.iterator();
// Iterator> iterator = list.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
// String item = (String) iterator.next();
System.out.println(item);
}
}
}

View File

@@ -0,0 +1,44 @@
package chapter6.demo61;
/**
* 商品类
*/
public class Goods {
private String name;
private double price;
private int num;
public Goods(String name, double price, int num) {
this.name = name;
this.price = price;
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String toString() {
return name + "\t" + price + "\t" + num;
}
}

View File

@@ -0,0 +1,85 @@
package chapter6.demo61;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class Manager {
static ArrayList goodsList = new ArrayList<>();
// static ArrayList<Goods> goodsList = new ArrayList<>();
public static void main(String[] args) {
Goods meizu = new Goods("魅族22", 3999, 11);
goodsList.add(meizu);
goodsList.add(new Goods("小米15", 6899, 10));
goodsList.add(new Goods("iPhone15", 5999, 2));
while (true) {
System.out.println("欢迎使用库房管理系统");
System.out.println("1. 商品入库");
System.out.println("2. 商品显示");
System.out.println("3. 商品出库");
System.out.print("请选择要进行的操作:");
Scanner sc = new Scanner(System.in);
int select = sc.nextInt();
switch (select) {
case 1:
addGoods();
System.out.println("商品入库成功,入库后仓库商品如下:");
showWareHouse();
break;
case 2:
showWareHouse();
break;
case 3:
System.out.print("请输入要出库的商品编号:");
int id = sc.nextInt();
removeGoods(id);
break;
}
}
}
// 商品入库
static void addGoods() {
Scanner sc = new Scanner(System.in);
System.out.print("商品名称:");
String name = sc.next();
System.out.print("商品价格:");
double price = sc.nextDouble();
System.out.print("商品数量:");
int num = sc.nextInt();
// Goods g = new Goods(name, price, num);
// goodsList.add(g);
goodsList.add(new Goods(name, price, num));
}
// 商品出库从goodList中删除指定位置的元素
static void removeGoods(int index) {
if (index >= 0 && index < goodsList.size()) {
goodsList.remove(index);
System.out.println("商品出库成功,出库后仓库商品如下:");
showWareHouse();
} else {
System.out.println("商品不存在!");
}
}
// 使用迭代器遍历商品
static void showWareHouse() {
System.out.println("==========================");
Iterator iterator = goodsList.iterator();
while (iterator.hasNext()) {
Goods goods = (Goods) iterator.next(); // 类型转换Object->Goods
System.out.println(goods);
}
System.out.println("==========================");
}
}

View File

@@ -0,0 +1,171 @@
package chapter6.demo62;
import java.util.LinkedList;
import java.util.Scanner;
public class Manager {
// 创建集合对象,用于存储学生数据
static LinkedList<Student> array = new LinkedList<Student>();
public static void main(String[] args) {
while(true) {
// 这是学生管理系统的主界面
System.out.println("--------欢迎来到学生管理系统--------");
System.out.println("1 查看所有学生");
System.out.println("2 添加学生");
System.out.println("3 删除学生");
System.out.println("4 修改学生");
System.out.println("5 退出");
System.out.println("请输入你的选择:");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch (choice) {
case 1:
showAllStudents();
break;
case 2:
addStudent();
break;
case 3:
deleteStudent();
break;
case 4:
updateStudent();
break;
default:
System.out.println("谢谢你的使用");
System.exit(0);
break;
}
}
}
// 查看所有学生
public static void showAllStudents() {
// 首先来判断集合中是否有数据,如果没有数据,就给出提示,并让该方法不继续往下执行
if (array.isEmpty()) {
System.out.println("不好意思,目前没有学生信息可供查询,请回去重新选择你的操作");
return;
}
System.out.println("学号\t姓名\t年龄\t居住地");
// 使用 foreach 循环遍历
for (Student s : array) {
System.out.println(s.getId() + "\t" + s.getName() + "\t" + s.getAge() + "\t" + s.getAddress());
}
}
// 添加学生
public static void addStudent() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生学号:");
String id = sc.nextLine();
// 判断学号有没有被人占用
// 定义标记
boolean flag = false;
// 遍历集合,得到每一个学生
for (Student s : array) {
if (s.getId().equals(id)) {
flag = true; // 说明学号被占用了
break;
}
}
if (flag) {
System.out.println("你输入的学号已经被占用,请重新输入:");
id = sc.nextLine();
}
System.out.println("请输入学生姓名:");
String name = sc.nextLine();
System.out.println("请输入学生年龄:");
int age = Integer.parseInt(sc.nextLine());
System.out.println("请输入学生居住地:");
String address = sc.nextLine();
// 添加学生到Array
array.add(new Student(id, name, age, address));
// 给出提示
System.out.println("添加学生成功");
}
// 删除学生
public static void deleteStudent() {
// 删除学生的思路:键盘录入一个学号,到集合中去查找,看是否有学生使用的是该学号,如果有就删除该学生
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要删除的学生的学号:");
String id = sc.nextLine();
// 我们必须给出学号不存在的时候的提示
// 定义一个索引
int index = -1;
// 遍历集合
for (int x = 0; x < array.size(); x++) {
// 获取到每一个学生对象
Student s = array.get(x);
// 拿这个学生对象的学号和键盘录入的学号进行比较
if (s.getId().equals(id)) {
index = x;
break;
}
}
if (index == -1) {
System.out.println("不好意思,你要删除的学号对应的学生信息不存在,请回去重新你的选择");
} else {
array.remove(index);
System.out.println("删除学生成功");
}
}
// 修改学生信息
public static void updateStudent() {
// 修改学生的思路:键盘录入一个学号,到集合中去查找,看是否有学生使用的是该学号,如果有就修改该学生
// 创建键盘录入对象
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要修改的学生的学号:");
String id = sc.nextLine();
// 定义一个索引
Student student = null;
// 遍历集合
for (int x = 0; x < array.size(); x++) {
// 获取每一个学生对象
Student s = array.get(x);
// 拿学生对象的学号和键盘录入的学号进行比较
if (s.getId().equals(id)) {
student = s;
break;
}
}
if (student == null) {
System.out.println("不好意思,你要修改的学号对应的学生信息不存在,请回去重新你的选择");
} else {
System.out.println("1 姓名");
System.out.println("2 年龄");
System.out.println("3 居住地");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("请输入学生新姓名:");
String name = sc.nextLine();
student.setName(name);
break;
case 2:
System.out.println("请输入学生新年龄:");
int age = sc.nextInt();
student.setAge(age);
break;
case 3:
System.out.println("请输入学生新居住地:");
String address = sc.nextLine();
student.setAddress(address);
break;
}
System.out.println("修改学生成功");
}
}
}

View File

@@ -0,0 +1,52 @@
package chapter6.demo62;
public class Student {
// 学号
private String id;
// 姓名
private String name;
// 年龄
private int age;
// 居住地
private String address;
// 构造方法
public Student(String id, String name, int age, String address) {
this.id = id;
this.name = name;
this.age = age;
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}

View File

@@ -0,0 +1,43 @@
package chapter6.demo64;
// Card.java - 扑克牌类
public class Card implements Comparable<Card> {
private final String color; // 花色
private final String point; // 点数
private final int index; // 编号
/**
* 构造一张扑克牌
* @param color 花色
* @param point 点数
* @param index 编号
*/
public Card(String color, String point, int index) {
this.color = color;
this.point = point;
this.index = index;
}
@Override
public String toString() {
return color + point;
}
@Override
public int compareTo(Card other) {
// if (this.index == other.index) {
// return 0;
// } else if (this.index > other.index) {
// return 1;
// } else {
// return -1;
// }
// 谁的index小谁排在前面
return this.index - other.index;
}
// getter方法
public int getIndex() {
return index;
}
}

View File

@@ -0,0 +1,45 @@
package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
// Deck.java - 牌组类
public class Deck {
private ArrayList<Card> cards = new ArrayList<>();
private static final String[] COLORS = {"", "", "", ""};
private static final String[] POINTS = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
/**
* 初始化一副扑克牌
*/
public Deck() {
int index = 0;
// 生成52张普通牌
for (String point : POINTS) {
for (String color : COLORS) {
cards.add(new Card(color, point, index++));
}
}
// 添加大小王
cards.add(new Card("", "小☺", index++));
cards.add(new Card("", "大☻", index));
}
/**
* 洗牌
*/
public void shuffle() {
Collections.shuffle(cards);
}
/**
* 发牌
* @return 发出的牌
*/
public Card dealCard() {
if (!cards.isEmpty()) {
return cards.removeFirst();
}
return null;
}
}

View File

@@ -0,0 +1,170 @@
package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Function {
// 存储牌号和牌面的对应关系
private static HashMap<Integer, String> cardMap = new HashMap<>();
public static void main(String[] args) {
// 1. 准备牌的基本元素
ArrayList<String> colors = prepareColors();
ArrayList<String> points = preparePoints();
// 2. 组装54张牌
createCards(colors, points);
// 3. 洗牌准备
ArrayList<Integer> cards = shuffleCards();
// 4. 发牌
ArrayList<ArrayList<Integer>> dealtCards = dealCards(cards);
ArrayList<Integer> iPlayer = dealtCards.get(0);
ArrayList<Integer> iPlayer2 = dealtCards.get(1);
ArrayList<Integer> iPlayer3 = dealtCards.get(2);
ArrayList<Integer> iSecretCards = dealtCards.get(3);
// 5. 整理手牌
sortCards(iPlayer, iPlayer2, iPlayer3);
// 6. 转换并显示牌面
showCards(iPlayer, iPlayer2, iPlayer3, iSecretCards);
}
/**
* 准备扑克牌的4种花色
* @return ArrayList<String> 包含4种花色符号的列表
*/
private static ArrayList<String> prepareColors() {
ArrayList<String> colors = new ArrayList<>();
colors.add("");
colors.add("");
colors.add("");
colors.add("");
return colors;
}
/**
* 准备扑克牌的13种点数
* @return ArrayList<String> 包含2-10,J,Q,K,A的点数列表
*/
private static ArrayList<String> preparePoints() {
ArrayList<String> points = new ArrayList<>();
for (int i = 2; i <= 10; i++) {
points.add(i + "");
}
points.add("J");
points.add("Q");
points.add("K");
points.add("A");
return points;
}
/**
* 创建54张扑克牌并建立编号和牌面的映射关系
* @param colors 花色列表
* @param points 点数列表
*/
private static void createCards(ArrayList<String> colors, ArrayList<String> points) {
int index = 0;
for (String number : points) {
for (String color : colors) {
cardMap.put(index++, color + number);
}
}
cardMap.put(index++, "小☺");
cardMap.put(index++, "大☻");
}
/**
* 生成54张牌的编号并随机打乱顺序
* @return ArrayList<Integer> 洗好的牌的编号列表(0-53)
*/
private static ArrayList<Integer> shuffleCards() {
ArrayList<Integer> cards = new ArrayList<>();
for (int i = 0; i <= 53; i++) {
cards.add(i);
}
Collections.shuffle(cards);
return cards;
}
/**
* 将54张牌分发给三个玩家和底牌
* @param cards 洗好的牌的编号列表
* @return ArrayList<ArrayList<Integer>> 包含四个列表的集合:
* 索引0-2分别为三个玩家的牌索引3为底牌
*/
private static ArrayList<ArrayList<Integer>> dealCards(ArrayList<Integer> cards) {
ArrayList<Integer> iPlayer = new ArrayList<>();
ArrayList<Integer> iPlayer2 = new ArrayList<>();
ArrayList<Integer> iPlayer3 = new ArrayList<>();
ArrayList<Integer> iSecretCards = new ArrayList<>();
for (int i = 0; i < cards.size(); i++) {
if (i >= 51) {
iSecretCards.add(cards.get(i));
} else {
if (i % 3 == 0) {
iPlayer.add(cards.get(i));
} else if (i % 3 == 1) {
iPlayer2.add(cards.get(i));
} else {
iPlayer3.add(cards.get(i));
}
}
}
ArrayList<ArrayList<Integer>> result = new ArrayList<>();
result.add(iPlayer);
result.add(iPlayer2);
result.add(iPlayer3);
result.add(iSecretCards);
return result;
}
/**
* 对玩家手中的牌进行排序
* @param players 可变参数,接收多个玩家的牌列表
*/
private static void sortCards(ArrayList<Integer>... players) {
for (ArrayList<Integer> player : players) {
Collections.sort(player);
}
}
/**
* 展示所有玩家的牌和底牌
* @param iPlayer 玩家1的牌号列表
* @param iPlayer2 玩家2的牌号列表
* @param iPlayer3 玩家3的牌号列表
* @param iSecretCards 底牌列表
*/
private static void showCards(ArrayList<Integer> iPlayer, ArrayList<Integer> iPlayer2,
ArrayList<Integer> iPlayer3, ArrayList<Integer> iSecretCards) {
ArrayList<String> sPlayer = convertToCardFace(iPlayer);
ArrayList<String> sPlayer2 = convertToCardFace(iPlayer2);
ArrayList<String> sPlayer3 = convertToCardFace(iPlayer3);
ArrayList<String> sSecretCards = convertToCardFace(iSecretCards);
System.out.println("玩家1" + sPlayer);
System.out.println("玩家2" + sPlayer2);
System.out.println("玩家3" + sPlayer3);
System.out.println("底牌:" + sSecretCards);
}
/**
* 将牌号转换为具体的牌面
* @param cards 牌号列表
* @return ArrayList<String> 转换后的牌面列表
*/
private static ArrayList<String> convertToCardFace(ArrayList<Integer> cards) {
ArrayList<String> result = new ArrayList<>();
for (Integer key : cards) {
result.add(cardMap.get(key));
}
return result;
}
}

View File

@@ -0,0 +1,73 @@
package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
// Game.java - 游戏类
public class Game {
private Deck deck;
private Player player1;
private Player player2;
private Player player3;
private ArrayList<Card> bottomCards;
/**
* 初始化游戏
*/
public Game() {
deck = new Deck();
player1 = new Player("玩家1");
player2 = new Player("玩家2");
player3 = new Player("玩家3");
bottomCards = new ArrayList<>();
}
/**
* 开始游戏
*/
public void start() {
// 1. 洗牌
deck.shuffle();
// 2. 发牌
for (int i = 0; i < 54; i++) {
Card card = deck.dealCard();
if (i >= 51) {
bottomCards.add(card);
} else {
switch (i % 3) {
case 0:
player1.receiveCard(card);
break;
case 1:
player2.receiveCard(card);
break;
case 2:
player3.receiveCard(card);
break;
}
}
}
// 3. 显示结果
showResult();
}
/**
* 显示游戏结果
*/
private void showResult() {
System.out.println(player1.showHand());
System.out.println(player2.showHand());
System.out.println(player3.showHand());
System.out.println("底牌:" + bottomCards);
}
/**
* 程序入口
*/
public static void main(String[] args) {
Game game = new Game();
game.start();
}
}

View File

@@ -0,0 +1,111 @@
package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
/* 第一步:准备扑克牌的基本元素 */
// 准备4种花色
ArrayList<String> colors = new ArrayList<String>();
colors.add("");
colors.add("");
colors.add("");
colors.add("");
// 准备13种点数2-10JQKA
ArrayList<String> point = new ArrayList<String>();
for (int i = 2; i <= 10; i++) {
point.add(i + "");
}
point.add("J");
point.add("Q");
point.add("K");
point.add("A");
/* 第二步组装54张扑克牌 */
// 用HashMap将每张牌的编号(0-53)与具体牌面对应起来
HashMap<Integer, String> map = new HashMap<Integer, String>();
int index = 0; // 牌的编号从0开始
// 两层循环生成52张普通牌13点数 × 4花色
for (String number : point) {
for (String color : colors) {
// 将花色与数字组合形成52张牌并赋予其编号
map.put(index++, color + number);
}
}
// 加入大小王编号为52和53
map.put(index++, "小☺");
map.put(index++, "大☻");
/* 第三步:洗牌准备 */
// 准备一个数字序列代表54张牌
ArrayList<Integer> cards = new ArrayList<Integer>();
for (int i = 0; i <= 53; i++) {
cards.add(i); // 此时的cards顺序为0-53
}
// 使用shuffle方法打乱牌的顺序洗牌
Collections.shuffle(cards);
/* 第四步:发牌 */
// 创建4个集合分别存储三个玩家的牌和底牌
ArrayList<Integer> iPlayer = new ArrayList<Integer>(); // 玩家1的牌
ArrayList<Integer> iPlayer2 = new ArrayList<Integer>(); // 玩家2的牌
ArrayList<Integer> iPlayer3 = new ArrayList<Integer>(); // 玩家3的牌
ArrayList<Integer> iSecretCards = new ArrayList<Integer>(); // 底牌
// 发牌规则留3张底牌其余轮流发给3个玩家
for (int i = 0; i < cards.size(); i++) {
if (i >= 51) {
iSecretCards.add(cards.get(i));// 留取3张底牌
} else {
if (i % 3 == 0) {
iPlayer.add(cards.get(i)); // 与3取余为0的牌发给玩家1
} else if (i % 3 == 1) {
iPlayer2.add(cards.get(i)); // 与3取余为1的牌发给玩家2
} else {
iPlayer3.add(cards.get(i)); // 其余的牌发给玩家3
}
}
}
/* 第五步:整理手牌 */
// 对每个玩家手中的牌排序
Collections.sort(iPlayer);
Collections.sort(iPlayer2);
Collections.sort(iPlayer3);
/* 第六步:转换牌面并显示 */
// iPlayer 中的存储的是每个玩家拥有的牌的编号0-53
// 将玩家手中的牌号转换为具体的牌面
ArrayList<String> sPlayer = new ArrayList<String>();
ArrayList<String> sPlayer2 = new ArrayList<String>();
ArrayList<String> sPlayer3 = new ArrayList<String>();
ArrayList<String> sSecretCards = new ArrayList<String>();
// 根据牌号从map中找出对应的牌面
for (Integer key : iPlayer) {
sPlayer.add(map.get(key));
}
for (Integer key : iPlayer2) {
sPlayer2.add(map.get(key));
}
for (Integer key : iPlayer3) {
sPlayer3.add(map.get(key));
}
for (Integer key : iSecretCards) {
sSecretCards.add(map.get(key));
}
// 展示每个玩家的牌
System.out.println("玩家1" + sPlayer);
System.out.println("玩家2" + sPlayer2);
System.out.println("玩家3" + sPlayer3);
System.out.println("底牌:" + sSecretCards);
}
}

View File

@@ -0,0 +1,37 @@
package chapter6.demo64;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;
// Player.java - 玩家类
public class Player {
private String name;
// Card类已经实现Comparable接口可以使用TreeSet自动排序
private TreeSet<Card> hand = new TreeSet<>();
/**
* 构造函数
* @param name 玩家名称
*/
public Player(String name) {
this.name = name;
}
/**
* 接收一张牌
* @param card 收到的牌
*/
public void receiveCard(Card card) {
hand.add(card);
}
/**
* 显示手牌
* @return 手牌的字符串表示
*/
public String showHand() {
return name + "" + hand.toString();
}
}

View File

@@ -0,0 +1,226 @@
本案例要求编写一个**斗地主的洗牌发牌**程序,要求按照斗地主的规则完成洗牌发牌的过程。
## 任务描述
一副扑克总共有54张牌牌面由花色和数字组成包括J、Q、K、A字母组成花色有♠、♥、♦、♣ 四种,分别表示黑桃、红桃、方块、梅花,小☺、大☻分别表示小王和大王。
斗地主游戏共有3位玩家参与首先将这54张牌的顺序打乱每人轮流摸一次牌剩余3张留作底牌然后在控制台打印3位玩家的牌和3张底牌。
## 运行结果
![](https://static.seahi.me/2024/12/202412030938880.png)
## 实现思路
### 1. 准备牌面元素
- 创建扑克牌的基本元素:花色和点数
- 花色:♠(黑桃)、♥(红桃)、♣(梅花)、♦(方块)
- 点数2-10、J、Q、K、A
- 使用`ArrayList`分别存储花色和点数
### 2. 生成完整的牌组
- 使用HashMap建立牌的编号和具体牌面的对应关系
- 通过两层循环组合花色和点数生成52张普通牌
- 额外加入大小王总共54张牌
- 每张牌都有唯一的编号(0-53)
### 3. 洗牌准备
- 创建一个包含0-53数字的ArrayList代表54张牌
- 使用`Collections.shuffle()`方法随机打乱这些数字的顺序
- 打乱后的顺序就是发牌的顺序
### 4. 发牌过程
- 创建4个ArrayList用于存储发牌结果
- 3个玩家的牌iPlayer1、iPlayer2、iPlayer3
- 1个底牌iSecretCards
- 发牌规则:
- 前51张牌轮流发给3个玩家i%3来分配
- 最后3张作为底牌
### 5. 整理手牌
- 使用`Collections.sort()`方法对每个玩家手中的牌进行排序
- 排序是对牌的编号进行排序,方便后续显示
### 6. 转换和显示
- 创建新的ArrayList存储实际的牌面字符串
- 遍历每个玩家手中的牌号
- 通过HashMap查找对应的牌面
- 最后打印每个玩家的牌和底牌
## 关键技术点
1. 集合的使用:
- ArrayList存储花色、点数和牌组
- HashMap建立编号和牌面的对应关系
2. 工具类的应用:
- Collections.shuffle():用于洗牌
- Collections.sort():用于整理手牌
3. 循环的应用:
- 两层循环生成牌组
- 取余操作(%)实现轮流发牌
## 示例代码
```java
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Main {
public static void main(String[] args) {
/* 第一步:准备扑克牌的基本元素 */
// 准备4种花色
ArrayList<String> colors = new ArrayList<String>();
colors.add("");
colors.add("");
colors.add("");
colors.add("");
// TODO 准备13种点数2-10JQKA
ArrayList<String> point = new ArrayList<String>();
/* 第二步组装54张扑克牌 */
// 用HashMap将每张牌的编号(0-53)与具体牌面对应起来
HashMap<Integer, String> map = new HashMap<Integer, String>();
int index = 0; // 牌的编号从0开始
// TODO 两层循环生成52张普通牌13点数 × 4花色
// 加入大小王编号为52和53
map.put(index++, "小☺");
map.put(index++, "大☻");
/* 第三步:洗牌准备 */
// TOOD 准备一个数字序列代表54张牌
ArrayList<Integer> cards = new ArrayList<Integer>();
// 使用shuffle方法打乱牌的顺序洗牌
Collections.shuffle(cards);
/* 第四步:发牌 */
// 创建4个集合分别存储三个玩家的牌和底牌
ArrayList<Integer> iPlayer = new ArrayList<Integer>(); // 玩家1的牌
ArrayList<Integer> iPlayer2 = new ArrayList<Integer>(); // 玩家2的牌
ArrayList<Integer> iPlayer3 = new ArrayList<Integer>(); // 玩家3的牌
ArrayList<Integer> iSecretCards = new ArrayList<Integer>(); // 底牌
// TODO 发牌规则留3张底牌其余轮流发给3个玩家
for (int i = 0; i < cards.size(); i++) {
}
/* 第五步:整理手牌 */
// 对每个玩家手中的牌排序
Collections.sort(iPlayer);
Collections.sort(iPlayer2);
Collections.sort(iPlayer3);
/* 第六步:转换牌面并显示 */
// iPlayer 中的存储的是每个玩家拥有的牌的编号0-53
// 将玩家手中的牌号转换为具体的牌面
ArrayList<String> sPlayer = new ArrayList<String>();
ArrayList<String> sPlayer2 = new ArrayList<String>();
ArrayList<String> sPlayer3 = new ArrayList<String>();
ArrayList<String> sSecretCards = new ArrayList<String>();
// TODO 根据牌号从map中找出对应的牌面
for (Integer key : iPlayer) {
sPlayer.add(map.get(key));
}
// 展示每个玩家的牌
System.out.println("玩家1" + sPlayer);
System.out.println("玩家2" + sPlayer2);
System.out.println("玩家3" + sPlayer3);
System.out.println("底牌:" + sSecretCards);
}
}
```
## 进阶任务
利用面向对象思想改造程序
### 类的设计级要求
#### 1. Card类扑克牌
**职责**:表示一张扑克牌
- 属性:
- suit花色字符串类型
- rank点数字符串类型
- index编号整型
- 功能:
- 构造方法:初始化一张牌
- toString方法返回牌面字符串
- 实现Comparable接口用于排序
#### 2. Deck类牌组
**职责**:管理一副完整的扑克牌
- 属性:
- cardsCard类型的ArrayList
- 花色和点数的常量数组
- 功能:
- 初始化54张牌
- 洗牌方法
- 发牌方法
#### 3. Player类玩家
**职责**:管理玩家信息和手牌
- 属性:
- name玩家名称
- hand存储手牌的ArrayList
- 功能:
- 接收牌
- 整理手牌
- 显示手牌
#### 4. Game类游戏管理
**职责**:控制游戏流程
- 属性:
- deck牌组对象
- 三个玩家对象
- bottomCards底牌列表
- 功能:
- 初始化游戏
- 执行游戏流程
- 显示游戏结果
### 改造要点
#### 1. 封装性要求
- 所有类的属性都应该是私有的
- 必要的属性提供getter/setter方法
- 对外只暴露必要的方法
#### 2. 类之间的关系
- Game类包含Deck类和Player类的对象
- Player类包含Card类的对象
- Deck类负责Card对象的创建和管理
#### 3. 功能性要求
- 保持原有程序的所有功能
- 洗牌和发牌的逻辑不变
- 结果显示格式保持一致

View File

@@ -0,0 +1,58 @@
package chapter7;
import java.io.File;
public class Example01 {
public static void main(String[] args) {
/**
* Step 1 创建普通文件
*/
File file1 = new File("out/chapter7/file1.txt");
if (file1.exists()) {
// 如果文件存在就删除
System.out.println("文件file1.txt存在");
file1.delete();
System.out.println("文件file1.txt已删除");
} else {
// 如果文件不存在就创建
System.out.println("文件file1.txt不存在");
try {
file1.createNewFile();
System.out.println("文件file1.txt已创建");
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("\n");
/**
* Step 2 创建目录
*/
File parent = file1.getParentFile();
if (! parent.exists()) {
// 如果父目录不存在就创建
System.out.println("父目录不存在");
parent.mkdirs();
System.out.println("父目录已创建");
}
if (file1.exists()) {
// 如果文件存在就删除
System.out.println("文件存在");
file1.delete();
System.out.println("文件已删除");
} else {
// 如果文件不存在就创建
System.out.println("文件不存在");
try {
file1.createNewFile();
System.out.println("文件已创建");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,16 @@
package chapter7;
import java.io.File;
public class Example03 {
public static void main(String[] args) {
File file = new File("src/chapter7");
if (file.isDirectory()) {
System.out.println("是目录");
String[] names = file.list();
for (String name : names) {
System.out.println(name);
}
}
}
}

View File

@@ -0,0 +1,39 @@
package chapter7;
import java.io.File;
import java.io.FilenameFilter;
public class Example04 {
public static void main(String[] args) {
// 创建 File 对象
File file = new File("src/chapter7");
// 创建过滤器对象
FilenameFilter filter = new FilenameFilter() {
// 实现 accept 方法
@Override
public boolean accept(File dir, String name) {
File currFile = new File(dir, name);
if (currFile.isFile() && name.endsWith(".java")) {
return true;
} else {
return false;
}
}
};
if (file.exists() && file.isDirectory()) {
String[] names = file.list(filter);
for (String name : names) {
System.out.println(name);
}
}
if (file.exists() && file.isDirectory()) {
File[] files = file.listFiles(filter);
for (File currentFile : files) {
System.out.println(currentFile);
}
}
}
}

View File

@@ -0,0 +1,27 @@
package chapter7;
import java.io.File;
public class Example05 {
public static void main(String[] args) {
File file = new File("src");
showFiles(file);
}
/**
* 显示指定目录下的所有文件
* @param dir 目录
*/
public static void showFiles(File dir) {
// 获取当前目录下所有文件的数组
File[] fileArray = dir.listFiles();
for (File file : fileArray) {
if (file.isDirectory()) {
// 如果是目录就递归调用
showFiles(file);
}
// 打印文件的绝对路径
System.out.println(file.getAbsolutePath());
}
}
}

View File

@@ -0,0 +1,16 @@
package chapter7;
import java.io.File;
public class Example06 {
public static void main(String[] args) {
File file = new File("resources");
if (file.exists()) {
if (file.delete()) {
System.out.println("删除成功!");
} else {
System.out.println("删除失败!");
}
}
}
}

View File

@@ -0,0 +1,32 @@
package chapter7;
import java.io.File;
public class Example07 {
public static void main(String[] args) {
File dir = new File("d:/hello");
deleteFiles(dir);
}
/**
* 删除指定目录下的所有文件(包括子目录)
* @param dir 目录
*/
public static void deleteFiles(File dir) {
if (dir.exists()) {
File[] files = dir.listFiles();
// 删除当前目录下的所有文件
for (File file : files) {
// 如果是目录就递归调用
if (file.isDirectory()) {
deleteFiles(file);
} else {
// 如果是文件就删除
file.delete();
}
}
// 删除当前目录
dir.delete();
}
}
}

View File

@@ -0,0 +1,19 @@
package chapter7;
import java.io.FileWriter;
import java.io.IOException;
public class Example08 {
public static void main(String[] args) {
// 使用try-with-resources自动关闭资源
try (FileWriter writer = new FileWriter("note.txt")) {
// 写入一些文本
writer.write("这是第一行\n"); // \n表示换行
writer.write("这是第二行\n");
System.out.println("文件写入成功!");
} catch (IOException e) {
System.out.println("写入文件出错:" + e.getMessage());
}
}
}

View File

@@ -0,0 +1,28 @@
package chapter7;
import java.io.FileWriter;
import java.io.IOException;
public class Example09 {
public static void main(String[] args) {
FileWriter writer = null; // 在try外声明以便finally中可以访问
try {
writer = new FileWriter("note.txt");
writer.write("这是第一行\n");
writer.write("这是第二行\n");
System.out.println("文件写入成功!");
} catch (IOException e) {
System.out.println("写入文件出错:" + e.getMessage());
} finally {
// 在finally中确保关闭资源
if (writer != null) { // 防止writer未初始化就抛出异常
try {
writer.close(); // close()方法也可能抛出IOException
} catch (IOException e) {
System.out.println("关闭文件出错:" + e.getMessage());
}
}
}
}
}

View File

@@ -0,0 +1,23 @@
package chapter7;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Example10 {
public static void main(String[] args) {
// 使用try-with-resources自动关闭资源
try (BufferedReader reader = new BufferedReader(
new FileReader("note.txt"))) {
String line;
// 逐行读取文件内容
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
System.out.println("读取文件出错:" + e.getMessage());
}
}
}

View File

@@ -0,0 +1,50 @@
package chapter7;
import java.io.*;
import java.util.Scanner;
public class FileOperationHomework {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 1. 获取文件名
System.out.print("请输入文件名:");
String fileName = scanner.nextLine();
// 2. 获取要写入的行数
System.out.print("请输入要写入的行数:");
int lines = scanner.nextInt();
scanner.nextLine(); // 消除换行符
// 3. 写入文件
try (FileWriter writer = new FileWriter(fileName)) {
// 循环获取用户输入并写入
for (int i = 1; i <= lines; i++) {
System.out.print("请输入第" + i + "行内容:");
String content = scanner.nextLine();
writer.write(content + "\n");
}
System.out.println("文件写入成功!");
} catch (IOException e) {
System.out.println("写入文件出错:" + e.getMessage());
return; // 如果写入出错,直接返回
}
// 4. 读取并显示文件内容
System.out.println("\n文件内容如下");
System.out.println("--------------------");
try (BufferedReader reader = new BufferedReader(
new FileReader(fileName))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
System.out.println("--------------------");
} catch (IOException e) {
System.out.println("读取文件出错:" + e.getMessage());
}
}
}

1
test.txt Normal file
View File

@@ -0,0 +1 @@
itcast

3
work.txt Normal file
View File

@@ -0,0 +1,3 @@
Java程序设计
大数据2班
2024年