zxy0307 commited on
Commit
0284885
·
verified ·
1 Parent(s): e9f1565

Upload 2300 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. API_project/.DS_Store +0 -0
  3. API_project/.idea/.gitignore +3 -0
  4. API_project/.idea/misc.xml +6 -0
  5. API_project/.idea/modules.xml +17 -0
  6. API_project/.idea/uiDesigner.xml +124 -0
  7. API_project/.idea/workspace.xml +50 -0
  8. API_project/API_project.iml +11 -0
  9. API_project/BigDecimal_module/BigDecimal_module.iml +11 -0
  10. API_project/BigDecimal_module/src/BigDecimal_package/BigDecimal_demo1.java +47 -0
  11. API_project/BigDecimal_module/src/BigDecimal_package/BigDecimal_demo2.java +36 -0
  12. API_project/BigInteger_module/BigInteger_module.iml +11 -0
  13. API_project/BigInteger_module/src/BigInteger_demo1.java +55 -0
  14. API_project/BigInteger_module/src/BigInteger_demo2.java +56 -0
  15. API_project/Date_module/Date_module.iml +11 -0
  16. API_project/Date_module/src/Calendar_package/Calendar_demo1.java +79 -0
  17. API_project/Date_module/src/Date_package/Date_demo1.java +32 -0
  18. API_project/Date_module/src/Date_package/Date_demo2.java +48 -0
  19. API_project/Date_module/src/Instant_package/Instant_demo1.java +59 -0
  20. API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo1.java +43 -0
  21. API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo2.java +27 -0
  22. API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo3.java +44 -0
  23. API_project/Date_module/src/ZoneId_package/ZoneId_demo1.java +27 -0
  24. API_project/Math_module/Math_module.iml +11 -0
  25. API_project/Math_module/src/Math_Case/IsPrime.java +17 -0
  26. API_project/Math_module/src/Math_Case/Narcissistic_number.java +28 -0
  27. API_project/Math_module/src/Math_package/Math_demo1.java +81 -0
  28. API_project/Object_Objects_module/Object_Objects_module.iml +11 -0
  29. API_project/Object_Objects_module/src/Object_package/Object_demo1.java +41 -0
  30. API_project/Object_Objects_module/src/Object_package/Object_demo2.java +39 -0
  31. API_project/Object_Objects_module/src/Object_package/Object_demo3.java +27 -0
  32. API_project/Object_Objects_module/src/Object_package/Student.java +47 -0
  33. API_project/Object_Objects_module/src/Object_package/User.java +106 -0
  34. API_project/Object_Objects_module/src/Objects_package/Objects_demo1.java +42 -0
  35. API_project/Object_Objects_module/src/Objects_package/Student.java +49 -0
  36. API_project/Packaging_module/Packaging_module.iml +11 -0
  37. API_project/Packaging_module/src/Case_package/case_demo1.java +51 -0
  38. API_project/Packaging_module/src/Case_package/case_demo2.java +38 -0
  39. API_project/Packaging_module/src/Case_package/case_demo3.java +37 -0
  40. API_project/Packaging_module/src/Case_package/case_demo4.java +40 -0
  41. API_project/Packaging_module/src/Case_package/case_demo5.java +39 -0
  42. API_project/Packaging_module/src/Integer_package/Integer_demo1.java +52 -0
  43. API_project/Packaging_module/src/Integer_package/Integer_demo2.java +35 -0
  44. API_project/Packaging_module/src/Integer_package/Integer_demo3.java +26 -0
  45. API_project/Regular_expression_module/Regular_expression_module.iml +11 -0
  46. API_project/Regular_expression_module/src/Regular_expression_Case_package/Regex_demo1.java +72 -0
  47. API_project/Regular_expression_module/src/Regular_expression_Case_package/Regex_demo2.java +65 -0
  48. API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo1.java +46 -0
  49. API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo2.java +68 -0
  50. API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo3.java +53 -0
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ IO_stream_project/Case_module/lib/hutool-all-5.8.10.jar filter=lfs diff=lfs merge=lfs -text
37
+ IO_stream_project/Commons_io_module/lib/hutool-all-5.8.10.jar filter=lfs diff=lfs merge=lfs -text
38
+ jigsaw_puzzle_project/jigsaw_puzzle_module/lib/hutool-all-5.8.10.jar filter=lfs diff=lfs merge=lfs -text
API_project/.DS_Store ADDED
Binary file (10.2 kB). View file
 
API_project/.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
API_project/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
API_project/.idea/modules.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/API_project.iml" filepath="$PROJECT_DIR$/API_project.iml" />
6
+ <module fileurl="file://$PROJECT_DIR$/BigDecimal_module/BigDecimal_module.iml" filepath="$PROJECT_DIR$/BigDecimal_module/BigDecimal_module.iml" />
7
+ <module fileurl="file://$PROJECT_DIR$/BigInteger_module/BigInteger_module.iml" filepath="$PROJECT_DIR$/BigInteger_module/BigInteger_module.iml" />
8
+ <module fileurl="file://$PROJECT_DIR$/Date_module/Date_module.iml" filepath="$PROJECT_DIR$/Date_module/Date_module.iml" />
9
+ <module fileurl="file://$PROJECT_DIR$/Math_module/Math_module.iml" filepath="$PROJECT_DIR$/Math_module/Math_module.iml" />
10
+ <module fileurl="file://$PROJECT_DIR$/Object_Objects_module/Object_Objects_module.iml" filepath="$PROJECT_DIR$/Object_Objects_module/Object_Objects_module.iml" />
11
+ <module fileurl="file://$PROJECT_DIR$/Packaging_module/Packaging_module.iml" filepath="$PROJECT_DIR$/Packaging_module/Packaging_module.iml" />
12
+ <module fileurl="file://$PROJECT_DIR$/Regular_expression_module/Regular_expression_module.iml" filepath="$PROJECT_DIR$/Regular_expression_module/Regular_expression_module.iml" />
13
+ <module fileurl="file://$PROJECT_DIR$/Runtime_module/Runtime_module.iml" filepath="$PROJECT_DIR$/Runtime_module/Runtime_module.iml" />
14
+ <module fileurl="file://$PROJECT_DIR$/System_module/System_module.iml" filepath="$PROJECT_DIR$/System_module/System_module.iml" />
15
+ </modules>
16
+ </component>
17
+ </project>
API_project/.idea/uiDesigner.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Palette2">
4
+ <group name="Swing">
5
+ <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
6
+ <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
7
+ </item>
8
+ <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
9
+ <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
10
+ </item>
11
+ <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
12
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
13
+ </item>
14
+ <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
15
+ <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
16
+ </item>
17
+ <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
18
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
19
+ <initial-values>
20
+ <property name="text" value="Button" />
21
+ </initial-values>
22
+ </item>
23
+ <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
24
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
25
+ <initial-values>
26
+ <property name="text" value="RadioButton" />
27
+ </initial-values>
28
+ </item>
29
+ <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
30
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
31
+ <initial-values>
32
+ <property name="text" value="CheckBox" />
33
+ </initial-values>
34
+ </item>
35
+ <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
36
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
37
+ <initial-values>
38
+ <property name="text" value="Label" />
39
+ </initial-values>
40
+ </item>
41
+ <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
42
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
43
+ <preferred-size width="150" height="-1" />
44
+ </default-constraints>
45
+ </item>
46
+ <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
47
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
48
+ <preferred-size width="150" height="-1" />
49
+ </default-constraints>
50
+ </item>
51
+ <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
52
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
53
+ <preferred-size width="150" height="-1" />
54
+ </default-constraints>
55
+ </item>
56
+ <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
57
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
58
+ <preferred-size width="150" height="50" />
59
+ </default-constraints>
60
+ </item>
61
+ <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
62
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
63
+ <preferred-size width="150" height="50" />
64
+ </default-constraints>
65
+ </item>
66
+ <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
67
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
68
+ <preferred-size width="150" height="50" />
69
+ </default-constraints>
70
+ </item>
71
+ <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
72
+ <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
73
+ </item>
74
+ <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
75
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
76
+ <preferred-size width="150" height="50" />
77
+ </default-constraints>
78
+ </item>
79
+ <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
80
+ <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
81
+ <preferred-size width="150" height="50" />
82
+ </default-constraints>
83
+ </item>
84
+ <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
85
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
86
+ <preferred-size width="150" height="50" />
87
+ </default-constraints>
88
+ </item>
89
+ <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
90
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
91
+ <preferred-size width="200" height="200" />
92
+ </default-constraints>
93
+ </item>
94
+ <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
95
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
96
+ <preferred-size width="200" height="200" />
97
+ </default-constraints>
98
+ </item>
99
+ <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
100
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
101
+ </item>
102
+ <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
103
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
104
+ </item>
105
+ <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
106
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
107
+ </item>
108
+ <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
109
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
110
+ </item>
111
+ <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
112
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
113
+ <preferred-size width="-1" height="20" />
114
+ </default-constraints>
115
+ </item>
116
+ <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
117
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
118
+ </item>
119
+ <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
120
+ <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
121
+ </item>
122
+ </group>
123
+ </component>
124
+ </project>
API_project/.idea/workspace.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AutoImportSettings">
4
+ <option name="autoReloadType" value="SELECTIVE" />
5
+ </component>
6
+ <component name="ChangeListManager">
7
+ <list default="true" id="0cb5cde6-a92c-4b5f-bb0c-e16e8a72a278" name="Changes" comment="" />
8
+ <option name="SHOW_DIALOG" value="false" />
9
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
+ <option name="LAST_RESOLUTION" value="IGNORE" />
12
+ </component>
13
+ <component name="FileTemplateManagerImpl">
14
+ <option name="RECENT_TEMPLATES">
15
+ <list>
16
+ <option value="Class" />
17
+ </list>
18
+ </option>
19
+ </component>
20
+ <component name="MarkdownSettingsMigration">
21
+ <option name="stateVersion" value="1" />
22
+ </component>
23
+ <component name="ProjectId" id="2LwMJI3MUGd9FuXiyDQaEdRUYdN" />
24
+ <component name="ProjectViewState">
25
+ <option name="autoscrollToSource" value="true" />
26
+ <option name="hideEmptyMiddlePackages" value="true" />
27
+ <option name="showLibraryContents" value="true" />
28
+ <option name="sortByType" value="true" />
29
+ </component>
30
+ <component name="PropertiesComponent"><![CDATA[{
31
+ "keyToString": {
32
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
33
+ "RunOnceActivity.ShowReadmeOnStart": "true",
34
+ "jdk.selected.JAVA_MODULE": "openjdk-18",
35
+ "last_opened_file_path": "/Users/zhaoxiaoyong/Documents/Code/Java/API_project",
36
+ "settings.editor.selected.configurable": "configurable.group.tools"
37
+ }
38
+ }]]></component>
39
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
40
+ <component name="TaskManager">
41
+ <task active="true" id="Default" summary="Default task">
42
+ <changelist id="0cb5cde6-a92c-4b5f-bb0c-e16e8a72a278" name="Changes" comment="" />
43
+ <created>1676777617776</created>
44
+ <option name="number" value="Default" />
45
+ <option name="presentableId" value="Default" />
46
+ <updated>1676777617776</updated>
47
+ </task>
48
+ <servers />
49
+ </component>
50
+ </project>
API_project/API_project.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/BigDecimal_module/BigDecimal_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/BigDecimal_module/src/BigDecimal_package/BigDecimal_demo1.java ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package BigDecimal_package;
2
+
3
+ import java.math.BigDecimal;
4
+
5
+ public class BigDecimal_demo1 {
6
+ public static void main(String[] args) {
7
+ /*
8
+ 构造方法获取BigDecimal对象
9
+ public BigDecimal (double val)
10
+ public BigDecimal (String val)
11
+
12
+ 静态方法获取BigDecimal对象
13
+ public static BigDecimal valueOf (double val)
14
+ */
15
+
16
+ //1、通过传递double类型的小数来创建对象
17
+ //细节:
18
+ //这种方式有可能是不精确的,所以不建议使用
19
+ BigDecimal bd1 = new BigDecimal(0.01);
20
+ BigDecimal bd2 = new BigDecimal(0.09);
21
+
22
+ System.out.println(bd1);
23
+ System.out.println(bd2);
24
+
25
+ //2、通过传递字符串表示的小数来创建对象
26
+ BigDecimal bd3 = new BigDecimal("0.01");
27
+ BigDecimal bd4 = new BigDecimal("0.09");
28
+ BigDecimal bd5 = bd3.add(bd4);
29
+ System.out.println(bd3);
30
+ System.out.println(bd4);
31
+ System.out.println(bd5);
32
+
33
+ //3、通过静态方法获取对象
34
+ BigDecimal bd6 = BigDecimal.valueOf(10);
35
+ BigDecimal bd7 = BigDecimal.valueOf(10);
36
+ System.out.println(bd6 == bd7);
37
+
38
+ //细节:
39
+ //1、如果要表示的数字不大,没有超出double的取值范围,建议使用静态方法
40
+ //2、如果要表示的数字比较大,超出了double的取值范围,建议使用构造方法
41
+ //3、如果我们传递的是0~10之间的整数,包含0,包含10,那么方法会返回已经创建好的对象,不会重新new
42
+
43
+ BigDecimal bd8 = BigDecimal.valueOf(10.0);
44
+ BigDecimal bd9 = BigDecimal.valueOf(10.0);
45
+ System.out.println(bd8 == bd9);
46
+ }
47
+ }
API_project/BigDecimal_module/src/BigDecimal_package/BigDecimal_demo2.java ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package BigDecimal_package;
2
+
3
+ import java.math.BigDecimal;
4
+ import java.math.RoundingMode;
5
+
6
+ public class BigDecimal_demo2 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ public BigDecimal add (BigDecimal val) 加法
10
+ public BigDecimal subtract (BigDecimal val) 减法
11
+ public BigDecimal multiply (BigDecimal val) 乘法
12
+ public BigDecimal divide (BigDecimal val) 除法
13
+ public BigDecimal divide (BigDecimal val, 精确几位, 舍入模式) 除法
14
+ */
15
+
16
+ //1、加法
17
+ BigDecimal bd1 = BigDecimal.valueOf(10.0);
18
+ BigDecimal bd2 = BigDecimal.valueOf(3.0);
19
+
20
+ BigDecimal bd3 = bd1.add(bd2);
21
+ System.out.println(bd3);
22
+
23
+ //2、减法
24
+ BigDecimal bd4 = bd1.subtract(bd2);
25
+ System.out.println(bd4);
26
+
27
+ //3、乘法
28
+ BigDecimal bd5 = bd1.multiply(bd2);
29
+ System.out.println(bd5);
30
+
31
+ //4、除法
32
+ BigDecimal bd6 = bd1.divide(bd2,2, RoundingMode.HALF_UP);
33
+ System.out.println(bd6);
34
+
35
+ }
36
+ }
API_project/BigInteger_module/BigInteger_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/BigInteger_module/src/BigInteger_demo1.java ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import java.math.BigInteger;
2
+ import java.util.Random;
3
+
4
+ public class BigInteger_demo1 {
5
+ public static void main(String[] args) {
6
+ /*
7
+ public BigInteger (int num, Random rnd) 获取随机大整数,范围:[0 ~ 2的num次方-1]
8
+ public BigInteger (String val) 获取指定的大整数
9
+ public BigInteger (String val, int radix) 获取指定进制的大整数
10
+
11
+ public static BigInteger valueOf (long val) 静态方法获取BigInteger的对象,
12
+ 内部有优化细节:对象一旦创建里面的数据不能发生改变。
13
+ */
14
+
15
+ //1、获取一个随机的大整数
16
+ Random r = new Random();
17
+ for (int i = 0; i < 100; i++) {
18
+ BigInteger bd1 = new BigInteger(4, r);
19
+ System.out.println(bd1);//[0, 15]
20
+ }
21
+
22
+ //2、获取一个指定的大整数
23
+ //细节:字符串中必须是整数,否则会报错
24
+ BigInteger bd2 = new BigInteger("99999999999");
25
+ System.out.println(bd2);
26
+
27
+ //3、获取指定进制的大整数
28
+ //细节:
29
+ //1、字符串中的数字必须是整数
30
+ //2、字符串中的数字必须要跟进制吻合
31
+ //比如二进制中,只能写0和1,写其他的就报错
32
+ BigInteger bd3 = new BigInteger("1000", 2);
33
+ System.out.println(bd3);
34
+
35
+ //4、静态方法获取BigInteger的对象,内部有优化
36
+ //细节:
37
+ //1、能表示范围比较小,在long的取值范围之类,如果超出long的范围就不行了
38
+ //2、在内部对常用的数字:-16~16进行了优化。
39
+ // 提前把-16~16先创建好BigInteger的对象,如果多次获取不会重新创建新的。
40
+ BigInteger bd5 = BigInteger.valueOf(16);
41
+ BigInteger bd6 = BigInteger.valueOf(16);
42
+ System.out.println(bd5 == bd6);//true
43
+
44
+ BigInteger bd7 = BigInteger.valueOf(17);
45
+ BigInteger bd8 = BigInteger.valueOf(17);
46
+ System.out.println(bd7 == bd8);//false
47
+
48
+ //5、对象一旦创建内部的数据不能发生改变
49
+ BigInteger bd9 = BigInteger.valueOf(1);
50
+ BigInteger bd10 = BigInteger.valueOf(2);
51
+ BigInteger result = bd9.add(bd10);
52
+ System.out.println(result);//3
53
+ //此时,不会修改参与计算的BigInteger对象中的值,而是产生了一个新的BigInteger对象记录3
54
+ }
55
+ }
API_project/BigInteger_module/src/BigInteger_demo2.java ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import java.math.BigInteger;
2
+
3
+ public class BigInteger_demo2 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public BigInteger add (BigInteger val) 加法
7
+ public BigInteger subtract (BigInteger val) 减法
8
+ public BigInteger multiply (BigInteger val) 乘法
9
+ public BigInteger divide (BigInteger val) 除法,获取商
10
+ public BigInteger[] divideAndRemainder (BigInteger val) 除法,获取商和余数
11
+ public boolean equals (Object x) 比较是否相同
12
+ public BigInteger pow (int exponent) 次幂
13
+ public BigInteger max/min (BigInteger val) 返回较大值/较小值
14
+ public int intValue (BigInteger val) 转为int类型整数,超出范围数据有误
15
+ */
16
+
17
+ //1、创建两个BigInteger对象
18
+ BigInteger bd1 = BigInteger.valueOf(10);
19
+ BigInteger bd2 = BigInteger.valueOf(3);
20
+
21
+ //2、加法
22
+ BigInteger bd3 = bd1.add(bd2);
23
+ System.out.println(bd3);
24
+
25
+ //3、除法,获取商和余数
26
+ BigInteger[] arr = bd1.divideAndRemainder(bd2);
27
+ System.out.println(arr.length);
28
+ System.out.println(arr[0]);
29
+ System.out.println(arr[1]);
30
+
31
+ //4、比较是否相同
32
+ boolean result = bd1.equals(bd2);
33
+ System.out.println(result);
34
+
35
+ //5、次幂
36
+ BigInteger bd4 = bd1.pow(2);
37
+ System.out.println(bd4);
38
+
39
+ //6、max
40
+ BigInteger bd5 = bd1.max(bd2);
41
+ System.out.println(bd5 == bd1);//true
42
+ System.out.println(bd5 == bd2);//false
43
+
44
+ //7、转为int类型整数,超出范围数据有误
45
+ int i = bd1.intValue();
46
+ System.out.println(i);
47
+
48
+ long l = bd5.longValue();
49
+ System.out.println(l);
50
+
51
+ double v = bd5.doubleValue();
52
+ System.out.println(v);
53
+
54
+
55
+ }
56
+ }
API_project/Date_module/Date_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/Date_module/src/Calendar_package/Calendar_demo1.java ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Calendar_package;
2
+
3
+ import java.util.Calendar;
4
+ import java.util.Date;
5
+
6
+ public class Calendar_demo1 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ public static Calendar getInstance () 获取当前时间的日历对象
10
+
11
+ public final Date getTime () 获取日期对象
12
+ public final setTime (Date date) 给日历设置日期对象
13
+
14
+ public long getTimeInMillis () 拿到时间毫秒值
15
+ public void setTimeInMillis (long millis) 给日历设置时间毫秒值
16
+
17
+ public int get (int field) 取日期中的某个字段信息
18
+ public void set (int field, int value) 修改日历的某个字段信息
19
+ public void add (int field, int amount) 为某个字段增加/减少指定的值
20
+ */
21
+
22
+ //1、获取日历对象
23
+ //细节1:Calendar 是一个抽象类,不能直接new,而是通过一个静态方法获取到子类对象
24
+ //底层原理:
25
+ //会根据系统的不同时区来获取不同的日历对象,默认表示当前时间
26
+ //会把时间中的纪元,年,月,日,时,分,秒,星期,等等的都放到一个数组当中
27
+ //0:纪元
28
+ //1:年
29
+ //2:月
30
+ //3:一年中的第几周
31
+ //4:一个月中的第几周
32
+ //5:一个月中的第几天(日期)
33
+ //……
34
+
35
+ //细节2:
36
+ //月份:范围0~11 如果获取出来的是1,那么实际上是2月
37
+ //星期:在老外的眼里,星期日是一周中的第一天
38
+ // 1(星期天) 2(星期一) 3(星期二) ……
39
+ Calendar c = Calendar.getInstance();
40
+ System.out.println(c);
41
+
42
+ //2、修改一下日历代表的时间
43
+ Date d = new Date(0L);
44
+ c.setTime(d);
45
+ System.out.println(c);
46
+
47
+
48
+ // public int get (int field) 取日期中的某个字段信息
49
+ // public void set (int field, int value) 修改日历的某个字段信息
50
+ // public void add (int field, int amount) 为某个字段增加/减少指定的值
51
+
52
+ c.set(Calendar.YEAR, 2000);
53
+ c.set(Calendar.MONTH, 11);
54
+
55
+ //调用方法在这个基础上增加一个月
56
+ c.add(Calendar.MONTH,1);
57
+
58
+ //java在Calendar类中,把索引对应的数字都定义成常量
59
+ int year = c.get(Calendar.YEAR);
60
+ int month = c.get(Calendar.MONTH) + 1;
61
+ int date = c.get(Calendar.DAY_OF_MONTH);
62
+ int week = c.get(Calendar.DAY_OF_WEEK);
63
+ System.out.println(year + ", " + month + ", " + date + ", " + getWeek(week));
64
+
65
+
66
+ }
67
+
68
+ //查表法:
69
+ //表:容器
70
+ //让数据跟索引产生对应的关系
71
+
72
+ //传入对应的数字:1~7
73
+ //返回对应的星期
74
+ public static String getWeek(int index) {
75
+ //定义一个数组,让汉字星期几 跟1~7产生对应关系
76
+ String[] arr = {"", "周日", "周一", "周二", "周三", "周四", "周五", "周六"};
77
+ return arr[index];
78
+ }
79
+ }
API_project/Date_module/src/Date_package/Date_demo1.java ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Date_package;
2
+
3
+ import java.util.Date;
4
+
5
+ public class Date_demo1 {
6
+ public static void main(String[] args) {
7
+ /*
8
+ public Date () 创建Date对象,表示当前时间
9
+ public Date (long date) 创建Date对象,表示指定时间
10
+
11
+ public void setTime (long time) 设置/修改毫秒值
12
+ public long getTime () 获取时间对象的毫秒值
13
+ */
14
+
15
+ //1、创建对象表示一个时间
16
+ Date d1 = new Date();
17
+ System.out.println(d1);
18
+
19
+ //2、创建对象表示一个指定的时间
20
+ Date d2 = new Date(0L);
21
+ System.out.println(d2);
22
+
23
+ //3、setTime 修改时间
24
+ //1000毫秒 = 1秒
25
+ d2.setTime(1000L);
26
+ System.out.println(d2);
27
+
28
+ //4、getTime获取当前时间的毫秒值
29
+ long time = d2.getTime();
30
+ System.out.println(time);
31
+ }
32
+ }
API_project/Date_module/src/Date_package/Date_demo2.java ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Date_package;
2
+
3
+ import java.util.Date;
4
+ import java.util.Random;
5
+
6
+ public class Date_demo2 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ 需求1:打印时间原点开始一年后的时间
10
+ 需求2:定义任意两个Date对象,比较一下哪个时间在前,哪个时间在后
11
+ */
12
+
13
+ //需求1:打印时间原点开始1年之后的时间
14
+ //1、创建一个对象,表示时间原点
15
+ Date d1 = new Date(0L);
16
+
17
+ //2、获取d1时间的毫秒值
18
+ long time = d1.getTime();
19
+
20
+ //3、在这个基础上我们要加一年的毫秒值
21
+ time += 1000L * 60 * 60 * 24 * 365;
22
+
23
+ //4、把计算之后的时间毫秒值,再设置回di当中
24
+ d1.setTime(time);
25
+
26
+ //5、打印d1
27
+ System.out.println(d1);
28
+
29
+
30
+ //需求2:定义任意两个Date对象,比较一下哪个时间在前,哪个时间在后
31
+ Random r = new Random();
32
+
33
+ //创建两个时间对象
34
+ Date d2 = new Date(Math.abs(r.nextInt()));
35
+ Date d3 = new Date(Math.abs(r.nextInt()));
36
+
37
+ long time2 = d2.getTime();
38
+ long time3 = d3.getTime();
39
+
40
+ if (time2 > time3) {
41
+ System.out.println("第一个时间在后,第二个时间在前");
42
+ } else if (time2 < time3) {
43
+ System.out.println("第一个时间在前,第二个时间在后");
44
+ } else {
45
+ System.out.println("两个时间一样");
46
+ }
47
+ }
48
+ }
API_project/Date_module/src/Instant_package/Instant_demo1.java ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Instant_package;
2
+
3
+ import java.net.SocketTimeoutException;
4
+ import java.time.Instant;
5
+ import java.time.ZoneId;
6
+ import java.time.ZonedDateTime;
7
+
8
+ public class Instant_demo1 {
9
+ public static void main(String[] args) {
10
+ /*
11
+ static Instant now () 获取当前时间的Instant对象(标准时间)
12
+ static Instant ofXxxx (long epochMilli) 根据(秒/毫秒/纳秒)获取Instant对象
13
+ ZonedDateTime atZone (ZoneId zone) 指定时区
14
+ boolean isXxx (Instant otherInstant) 判断系列的方法
15
+ Instant minusXxx (long millisToSubtract) 减少时间系列的方法
16
+ Instant plusXxx (long millisToSubtract) 增加时间系列的方法
17
+ */
18
+
19
+ //1、获取当前时间的Instant对象(标准时间)
20
+ Instant now = Instant.now();
21
+ System.out.println(now);
22
+
23
+ //2、根据(秒/毫秒/纳秒)获取Instant对象
24
+ Instant instant1 = Instant.ofEpochMilli(0L);
25
+ System.out.println(instant1);
26
+
27
+ Instant instant2 = Instant.ofEpochSecond(1L);
28
+ System.out.println(instant2);
29
+
30
+ Instant instant3 = Instant.ofEpochSecond(1L, 1000000000L);
31
+ System.out.println(instant3);
32
+
33
+ //3、指定时区
34
+ ZonedDateTime time = Instant.now().atZone(ZoneId.of("America/Cuiaba"));
35
+ System.out.println(time);
36
+
37
+ //4、isXxx 判断
38
+ Instant instant4 = Instant.ofEpochMilli(0L);
39
+ Instant instant5 = Instant.ofEpochMilli(1000L);
40
+
41
+ //isBefore:判断调用者代表的时间是否在参数表示时间的前面
42
+ boolean result1 = instant4.isBefore(instant5);
43
+ System.out.println(result1);//true
44
+
45
+ //isAfter:判断调用者代表的时间是否在参数表示时间的后面
46
+ boolean result2 = instant4.isAfter(instant5);
47
+ System.out.println(result2);//false
48
+
49
+ //5、Instant minusXxx (long millisToSubtract) 减少时间系列的方法
50
+ Instant instant6 = Instant.ofEpochMilli(324567234L);
51
+ System.out.println(instant6);//1970-01-04T18:09:27.234Z
52
+
53
+ Instant instant7 = instant6.minusSeconds(1);
54
+ System.out.println(instant7);//1970-01-04T18:09:26.234Z
55
+
56
+ //6、
57
+
58
+ }
59
+ }
API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo1.java ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package SimpleDateFormat_package;
2
+
3
+ import java.text.ParseException;
4
+ import java.text.SimpleDateFormat;
5
+ import java.util.Date;
6
+
7
+ public class SimpleDateFormat_demo1 {
8
+ public static void main(String[] args) throws ParseException {
9
+ /*
10
+ public SimpleDateFormat () 默认格式
11
+ public SimpleDateFormat (String pattern) 指定格式
12
+
13
+ public final String format (Date date) 格式化(日期对象 -> 字符串)
14
+ public Date parse (String source) 解析(字符串 -> 日期对象)
15
+ */
16
+
17
+ //method();
18
+
19
+ //1、定义一个字符串表示时间
20
+ String str="2023-11-11 11:23:54";
21
+ //2、利用带参构造创建SimpleDateFormat对象,指定格式
22
+ //细节:
23
+ //创建对象的格式要跟字符串的格式完全一致
24
+ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
25
+ Date date = sdf.parse(str);
26
+ //3、打印结果
27
+ System.out.println(date);
28
+
29
+ }
30
+
31
+ private static void method() {
32
+ //1、利用空参构造创建SimpleDateFormat对象,默认格式
33
+ SimpleDateFormat sdf = new SimpleDateFormat();
34
+ Date d = new Date();
35
+ String str = sdf.format(d);
36
+ System.out.println(str);// 2023/2/21 上午11:28
37
+
38
+ //2、利用带参构造创建SimpleDateFormat对象,指定格式
39
+ SimpleDateFormat sdf2=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss EE");
40
+ String str2=sdf2.format(d);
41
+ System.out.println(str2);// 2023年02月21日 11:28:07 周二
42
+ }
43
+ }
API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo2.java ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package SimpleDateFormat_package;
2
+
3
+ import java.text.ParseException;
4
+ import java.text.SimpleDateFormat;
5
+ import java.util.Date;
6
+
7
+ public class SimpleDateFormat_demo2 {
8
+ public static void main(String[] args) throws ParseException {
9
+ /*
10
+ 假设,你初恋的出生年月日为:2000-11-11
11
+ 请用字符串表示这个数据,并将其转换为:2000年11月11日
12
+ */
13
+
14
+ //1、可以通过2000-11-11进行解析,解析成一个Date对象
15
+ String str = "2000-11-11";
16
+ //2、解析
17
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
18
+ Date date = sdf1.parse(str);
19
+
20
+ //3、格式化
21
+ SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
22
+ String result = sdf2.format(date);
23
+ System.out.println(result);
24
+
25
+
26
+ }
27
+ }
API_project/Date_module/src/SimpleDateFormat_package/SimpleDateFormat_demo3.java ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package SimpleDateFormat_package;
2
+
3
+ import java.text.ParseException;
4
+ import java.text.SimpleDateFormat;
5
+ import java.util.Date;
6
+
7
+ public class SimpleDateFormat_demo3 {
8
+ public static void main(String[] args) throws ParseException {
9
+ /*
10
+ 需求:
11
+ 秒杀活动:2023年11月11日 0:0:0
12
+ 结束时间:2023年11月11日 0:10:0
13
+
14
+ 小贾下单并付款的时间为:2023年11月11日 0:01:00
15
+ 小皮下单并付款的时间为:2023年11月11日 0:11:0
16
+ 用代码说明这两个同学有没有参加上秒杀活动?
17
+
18
+ */
19
+
20
+ //1、定义字符串表示三个时间
21
+ String startStr = "2023年11月11日 0:0:0";
22
+ String endStr = "2023年11月11日 0:10:0";
23
+ String orderStr = "2023年11月11日 0:11:0";
24
+
25
+ //2、解析上面的三个时间,得到Date对象
26
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
27
+ Date startDate = sdf.parse(startStr);
28
+ Date endDate = sdf.parse(endStr);
29
+ Date orderDate = sdf.parse(orderStr);
30
+
31
+ //3、得到三个时间的毫秒值
32
+ long startTime = startDate.getTime();
33
+ long endTime = endDate.getTime();
34
+ long orderTime = orderDate.getTime();
35
+
36
+ //4、判断
37
+ if (orderTime >= startTime && orderTime <= endTime) {
38
+ System.out.println("参加秒杀活动成功");
39
+ } else {
40
+ System.out.println("参加秒杀活动失败");
41
+ }
42
+
43
+ }
44
+ }
API_project/Date_module/src/ZoneId_package/ZoneId_demo1.java ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package ZoneId_package;
2
+
3
+ import java.time.ZoneId;
4
+ import java.util.Set;
5
+
6
+ public class ZoneId_demo1 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ static Set<String> getAvailableZoneIds () 获取java中支持的所有时区
10
+ static ZoneId systemDefault () 获取系统默认时区
11
+ static ZoneId of (String zoneId) 获取一个指定时区
12
+ */
13
+
14
+ //1、获取所有的时区名称
15
+ Set<String> zoneIds = ZoneId.getAvailableZoneIds();
16
+ System.out.println(zoneIds.size());
17
+ System.out.println(zoneIds);
18
+
19
+ //2、获取当前系统的默认时区
20
+ ZoneId zoneId = ZoneId.systemDefault();
21
+ System.out.println(zoneId);
22
+
23
+ //3、获取指定的时区
24
+ ZoneId zoneId1 = ZoneId.of("America/Cuiaba");
25
+ System.out.println(zoneId1);
26
+ }
27
+ }
API_project/Math_module/Math_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/Math_module/src/Math_Case/IsPrime.java ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Math_Case;
2
+
3
+ public class IsPrime {
4
+ public static void main(String[] args) {
5
+ //判断一个数是否为一个质数
6
+ System.out.println(isPrime(998));
7
+ }
8
+
9
+ private static boolean isPrime(int number) {
10
+ for (int i = 2; i <= Math.sqrt(number); i++) {
11
+ if (number % i == 0) {
12
+ return false;
13
+ }
14
+ }
15
+ return true;
16
+ }
17
+ }
API_project/Math_module/src/Math_Case/Narcissistic_number.java ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Math_Case;
2
+
3
+ public class Narcissistic_number {
4
+ public static void main(String[] args) {
5
+ //要求1:统计一共有多少个水仙花数
6
+
7
+ //水仙花数:100~999
8
+ int count = 0;
9
+ //得到每一个三位数
10
+ for (int i = 100; i <= 999; i++) {
11
+ //个位 十位 百位
12
+ int ge = i % 10;
13
+ int shi = i / 10 % 10;
14
+ int bai = i / 100 % 10;
15
+
16
+ //判断:
17
+ //每一位的三次方之后 跟本身 进行比较
18
+ double sum = Math.pow(ge, 3) + Math.pow(shi, 3) + Math.pow(bai, 3);
19
+
20
+ if (sum == i) {
21
+ count++;
22
+ System.out.println(i);
23
+ }
24
+ }
25
+
26
+ System.out.println(count);
27
+ }
28
+ }
API_project/Math_module/src/Math_package/Math_demo1.java ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Math_package;
2
+
3
+ public class Math_demo1 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public static int abs(int a) 获取参数绝对值
7
+ public static double ceil(double a) 向上取整
8
+ public static double floor(double a) 向下取整
9
+ public static int round(float a) 四舍五入
10
+ public static int max(int a, int b) 获取两个int值中的较大值
11
+ public static double pow(double a, double b) 返回a的b次幂的值
12
+ public static double sqrt(double a) 返回a的平方根
13
+ public static double cbrt(double a) 返回a的立方根
14
+ public static double random() 返回值为double的随机值,范围[0.0, 1.0)
15
+ */
16
+
17
+ //abs 获取参数绝对值
18
+ System.out.println(Math.abs(-88));
19
+ System.out.println(Math.abs(88));
20
+ //bug:
21
+ //以int类型为例,取值范围: -2147483648 ~ 2147483647
22
+ //如果没有正数与负数对应,那么传递负数结果有误
23
+ //-2147483648 没有正数与之对应,所以abs结果产生bug
24
+ System.out.println(Math.abs(-2147483648));
25
+ //System.out.println(Math.absExact(-2147483648));
26
+ System.out.println("-----------------------");
27
+
28
+ //进一法:往数轴的正方向进一
29
+ System.out.println(Math.ceil(12.34));
30
+ System.out.println(Math.ceil(12.54));
31
+ System.out.println(Math.ceil(-12.34));
32
+ System.out.println(Math.ceil(-12.54));
33
+ System.out.println("-----------------------");
34
+
35
+ //去尾法:往数轴的负方向进一
36
+ System.out.println(Math.floor(12.34));
37
+ System.out.println(Math.floor(12.54));
38
+ System.out.println(Math.floor(-12.34));
39
+ System.out.println(Math.floor(-12.54));
40
+ System.out.println("-----------------------");
41
+
42
+ //public static int round(float a) 四舍五入
43
+ System.out.println(Math.round(12.34));
44
+ System.out.println(Math.round(12.54));
45
+ System.out.println(Math.round(-12.34));
46
+ System.out.println(Math.round(-12.54));
47
+ System.out.println("-----------------------");
48
+
49
+ //public static int max(int a, int b) 获取两个int值中的较大值
50
+ System.out.println(Math.max(20, 30));
51
+ System.out.println("-----------------------");
52
+
53
+ //获取两个整数的较小值
54
+ System.out.println(Math.min(20, 30));
55
+ System.out.println("-----------------------");
56
+
57
+ //获取a的b次幂
58
+ System.out.println(Math.pow(2, 3));
59
+ //细节:
60
+ //如果第二个参数 0~1之间的小数
61
+ System.out.println(Math.pow(4, 0.5));
62
+ System.out.println(Math.pow(2, -2));
63
+ //建议:
64
+ //第二个参数:一般传递大于等于1的正整数
65
+ System.out.println("-----------------------");
66
+
67
+ System.out.println(Math.sqrt(4));
68
+ System.out.println(Math.cbrt(8));
69
+ System.out.println("-----------------------");
70
+
71
+ for (int i = 0; i < 10; i++) {
72
+ System.out.println(Math.floor(Math.random() * 100) + 1);
73
+ //Math.random() [0.0 , 1.0)
74
+ //* 100 [0.0 , 100.0)
75
+ //floor 去掉了后面的小数
76
+ //+1 [1.0 , 100.0]
77
+ }
78
+
79
+
80
+ }
81
+ }
API_project/Object_Objects_module/Object_Objects_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/Object_Objects_module/src/Object_package/Object_demo1.java ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Object_package;
2
+
3
+ public class Object_demo1 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public String toString() 返回对象的字符串表示形式
7
+ public boolean equals(Object obj) 比较两个对象是否相等
8
+ protected Object clone(int a) 对象克隆
9
+ */
10
+
11
+ //1、toString() 返回对象的字符串表示形式
12
+ Object obj = new Object();
13
+ String str = obj.toString();
14
+ System.out.println(str);//java.lang.Object@372f7a8d
15
+
16
+ //细节:
17
+ //System:类名
18
+ //out:静态变量
19
+ //System.out:获取打印的对象
20
+ //println():方法
21
+ //参数:表示打印的内容
22
+ //核心逻辑:
23
+ //当我们打印一个对象的时候,底层会调用对象的toString方法,把对象变成字符串
24
+ //然后再打印到控制台上,打印完毕换行处理。
25
+ System.out.println(obj);//java.lang.Object@372f7a8d
26
+
27
+
28
+ //思考:默认情况下,因为Object类中的toString方法返回的是地址值
29
+ //所以,默认情况下,打印一个对象打印的就是地址值
30
+ //但是地址值对于我们是没什么意义的
31
+ //我想要看到对象内部的属性值,我们该怎么办?
32
+ //处理方案:重写父类Object类中的toString方法
33
+ Student stu = new Student("张三", 23);
34
+ System.out.println(stu);
35
+
36
+ //toString方法的结论:
37
+ //如果我们打印一个对象,想要看到属性值的话,那么就重写toString方法就可以了
38
+ //在重写的方法中,把对象的属性值进行拼接
39
+
40
+ }
41
+ }
API_project/Object_Objects_module/src/Object_package/Object_demo2.java ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Object_package;
2
+
3
+ public class Object_demo2 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public boolean equals(Object obj) 比较两个对象是否相等
7
+ */
8
+
9
+ Student s1 = new Student();
10
+ Student s2 = new Student();
11
+
12
+ boolean result1 = s1.equals(s2);
13
+ System.out.println(result1);//true
14
+
15
+ //结论:
16
+ //1、如果没有重写equals方法,那么默认使用Object中的方法进行比较,比较的是地址值是否相同
17
+ //2、一般来讲地址值对于我们意义不大,所以我们会重写,重写之后比较的就是对象内部的属性值
18
+
19
+ String s="abc";
20
+ StringBuilder sb=new StringBuilder("abc");
21
+
22
+ System.out.println(s.equals(sb));//false
23
+ //因为equals方法是被s调用的,而s是字符串
24
+ //所以equals要看String类中的
25
+
26
+ //字符串中的equals方法,先判断参数是否为字符串
27
+ //如果是字符串,再比较内部的属性
28
+ //但是如果参数不是字符串,直接返回false
29
+
30
+ System.out.println(sb.equals(s));//false
31
+ //因为equals方法是被sb调用的,而sb是StringBuilder
32
+ //所以这里的equals方法要看StringBuilder中的equals方法
33
+
34
+ //那么在StringBuilder当中,没有重写equals方法
35
+ //使用的是Object中的
36
+ //在Object当中默认是使用==号比较两个对象的地址值
37
+ //而这里的s和sb记录的地址值是不一样的,所以结果返回false
38
+ }
39
+ }
API_project/Object_Objects_module/src/Object_package/Object_demo3.java ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Object_package;
2
+
3
+ public class Object_demo3 {
4
+ public static void main(String[] args) throws CloneNotSupportedException {
5
+ //protected Object clone(int a) 对象克隆
6
+
7
+ //1、先创建一个对象
8
+ int[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0};
9
+ User u1 = new User(1, "张三", "1234qwer", "girl111", data);
10
+
11
+ //2、克隆对象
12
+ //细节:
13
+ //方法在底层会帮我们创建一个对象,并把原对象中的数据拷贝过去
14
+ //书写细节:
15
+ //1、重写Object中的clone方法
16
+ //2、让javabean类实现Cloneable接口
17
+ //3、创建原对象并调用clone方法就可以了
18
+ User u2 = (User) u1.clone();
19
+
20
+ //验证一件事情:Object中的克隆是浅克隆
21
+ int[] arr = u1.getData();
22
+ arr[0] = 100;
23
+ System.out.println(u1);
24
+ System.out.println(u2);
25
+
26
+ }
27
+ }
API_project/Object_Objects_module/src/Object_package/Student.java ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Object_package;
2
+
3
+ import java.util.Objects;
4
+
5
+ public class Student {
6
+ private String name;
7
+ private int age;
8
+
9
+ public Student(String name, int age) {
10
+ this.name = name;
11
+ this.age = age;
12
+ }
13
+
14
+ public Student() {
15
+ }
16
+
17
+ public String getName() {
18
+ return name;
19
+ }
20
+
21
+ public void setName(String name) {
22
+ this.name = name;
23
+ }
24
+
25
+ public int getAge() {
26
+ return age;
27
+ }
28
+
29
+ public void setAge(int age) {
30
+ this.age = age;
31
+ }
32
+
33
+ @Override
34
+ public String toString() {
35
+ return name + ", " + age;
36
+ }
37
+
38
+ //重写之后的equals方法比较的就是对象内部的属性值
39
+ @Override
40
+ public boolean equals(Object o) {
41
+ if (this == o) return true;
42
+ if (o == null || getClass() != o.getClass()) return false;
43
+ Student student = (Student) o;
44
+ return age == student.age && Objects.equals(name, student.name);
45
+ }
46
+
47
+ }
API_project/Object_Objects_module/src/Object_package/User.java ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Object_package;
2
+
3
+ import java.util.Arrays;
4
+ import java.util.StringJoiner;
5
+
6
+ //Cloneable
7
+ //如果一个接口里面没有抽象方法
8
+ //表示当前的接口是一个标记性接口
9
+ //现在Cloneable表示一旦实现了,那么当前类的对象就可以被克隆
10
+ //如果没有实现,当前类的对象就不能克隆
11
+ public class User implements Cloneable {
12
+ private int id;//游戏角色
13
+ private String username;//用户名
14
+ private String password;//密码
15
+ private String path;//游戏图片
16
+ private int[] data;//游戏进度
17
+
18
+ public User(int id, String username, String password, String path, int[] data) {
19
+ this.id = id;
20
+ this.username = username;
21
+ this.password = password;
22
+ this.path = path;
23
+ this.data = data;
24
+ }
25
+
26
+ public User() {
27
+ }
28
+
29
+ public int getId() {
30
+ return id;
31
+ }
32
+
33
+ public void setId(int id) {
34
+ this.id = id;
35
+ }
36
+
37
+ public String getUsername() {
38
+ return username;
39
+ }
40
+
41
+ public void setUsername(String username) {
42
+ this.username = username;
43
+ }
44
+
45
+ public String getPassword() {
46
+ return password;
47
+ }
48
+
49
+ public void setPassword(String password) {
50
+ this.password = password;
51
+ }
52
+
53
+ public String getPath() {
54
+ return path;
55
+ }
56
+
57
+ public void setPath(String path) {
58
+ this.path = path;
59
+ }
60
+
61
+ public int[] getData() {
62
+ return data;
63
+ }
64
+
65
+ public void setData(int[] data) {
66
+ this.data = data;
67
+ }
68
+
69
+ @Override
70
+ public String toString() {
71
+ return "角色编号为:" + id +
72
+ ", 用户名:" + username +
73
+ ", 密码:" + password +
74
+ ", 游戏图片:'" + path +
75
+ ", 进度:" + arrToString();
76
+ }
77
+
78
+ public String arrToString() {
79
+ StringJoiner sj = new StringJoiner(",", "[", "]");
80
+ for (int i = 0; i < data.length; i++) {
81
+ sj.add(data[i] + "");
82
+ }
83
+ return sj.toString();
84
+ }
85
+
86
+ @Override
87
+ protected Object clone() throws CloneNotSupportedException {
88
+ //调用父类中的clone方法
89
+ //相当于让Java帮我们克隆一个对象,并把克隆之后的对象返回出去
90
+
91
+ //先把被克隆对象中的数组获取出来
92
+ int[] data = this.data;
93
+ //创建新的数组
94
+ int[] newData = new int[data.length];
95
+ //拷贝数组中的数据
96
+ for (int i = 0; i < data.length; i++) {
97
+ newData[i] = data[i];
98
+ }
99
+
100
+ //调用父类中的方法克隆对象
101
+ User u = (User) super.clone();
102
+ //因为父类中的克隆方法是浅克隆,替换克隆出来对象中的数组地址值
103
+ u.data = newData;
104
+ return u;
105
+ }
106
+ }
API_project/Object_Objects_module/src/Objects_package/Objects_demo1.java ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Objects_package;
2
+
3
+ import java.util.Objects;
4
+
5
+ public class Objects_demo1 {
6
+ public static void main(String[] args) {
7
+ /*
8
+ public static boolean equals (Object a, Object b) 先做非空判断,比较两个对象
9
+ public static boolean isNull (Object obj) 判断对象是否为null,为null返回true,反之
10
+ public static boolean nonNull (Object obj) 判断对象是否为null,跟isNull的结果相反
11
+ */
12
+
13
+ //1、创建学生类的对象
14
+ Student s1 = null;
15
+ Student s2 = new Student("张三", 23);
16
+
17
+ //2、比较两个对象的属性值是否相同
18
+ // if (s1 != null) {
19
+ // boolean result = s1.equals(s2);
20
+ // System.out.println(result);
21
+ // } else {
22
+ // System.out.println("调用者为空");
23
+ // }
24
+
25
+ boolean result = Objects.equals(s1, s2);
26
+ System.out.println(result);
27
+ //细节:
28
+ //1、方法的底层会判断s1是否为null,如果为null,直接返回false
29
+ //2、如果s1不为null,那么就利用s1再次调用equals方法
30
+ //3、此时s1是Student类型,所以最终还是会调用Student中的equals方法
31
+ // 如果没有重写,比较地址值,如果重写了,就比较属性值
32
+
33
+
34
+ //public static boolean isNull (Object obj) 判断对象是否为null,为null返回true,反之
35
+ Student s3 = new Student();
36
+ System.out.println(Objects.isNull(s3));
37
+ System.out.println(Objects.isNull(s1));
38
+
39
+ System.out.println(Objects.nonNull(s3));
40
+ System.out.println(Objects.nonNull(s1));
41
+ }
42
+ }
API_project/Object_Objects_module/src/Objects_package/Student.java ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Objects_package;
2
+
3
+ import java.util.Objects;
4
+
5
+ public class Student {
6
+ private String name;
7
+ private int age;
8
+
9
+ public Student() {
10
+ }
11
+
12
+ public Student(String name, int age) {
13
+ this.name = name;
14
+ this.age = age;
15
+ }
16
+
17
+ public String getName() {
18
+ return name;
19
+ }
20
+
21
+ public void setName(String name) {
22
+ this.name = name;
23
+ }
24
+
25
+ public int getAge() {
26
+ return age;
27
+ }
28
+
29
+ public void setAge(int age) {
30
+ this.age = age;
31
+ }
32
+
33
+ @Override
34
+ public boolean equals(Object o) {
35
+ if (this == o) return true;
36
+ if (o == null || getClass() != o.getClass()) return false;
37
+ Student student = (Student) o;
38
+ return age == student.age && Objects.equals(name, student.name);
39
+ }
40
+
41
+
42
+ @Override
43
+ public String toString() {
44
+ return "Student{" +
45
+ "name='" + name + '\'' +
46
+ ", age=" + age +
47
+ '}';
48
+ }
49
+ }
API_project/Packaging_module/Packaging_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/Packaging_module/src/Case_package/case_demo1.java ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Case_package;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.Scanner;
5
+
6
+ public class case_demo1 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ 键盘录入一些1~100之间的整数,并添加到集合中。
10
+ 直到集合中所有数据和超过200为止。
11
+ */
12
+
13
+ //1、创建一个集合用来添加整数
14
+ ArrayList<Integer> list = new ArrayList<>();
15
+
16
+ //2、键盘录入数据添加到集合中
17
+ while (true) {
18
+ System.out.println("请输入一个整数:");
19
+ Scanner sc = new Scanner(System.in);
20
+ String numStr = sc.nextLine();
21
+ int num = Integer.parseInt(numStr);
22
+
23
+ //先把异常数据先进行过滤
24
+ if (num < 1 || num > 100) {
25
+ System.out.println("当前数字不在1~100的范围当中,请重新输入");
26
+ continue;
27
+ }
28
+ //添加到集合中
29
+ //细节:
30
+ //num:基本数据类型
31
+ //集合里面的数据是Integer
32
+ //在添加数据的时候触发了自动装箱
33
+ list.add(num);
34
+
35
+ //统计集合中所有的数据和
36
+ int sum = getSum(list);
37
+ if (sum > 200) {
38
+ System.out.println("集合中所有的数据和已经满足要求");
39
+ break;
40
+ }
41
+ }
42
+ }
43
+
44
+ private static int getSum(ArrayList<Integer> list) {
45
+ int sum = 0;
46
+ for (int i = 0; i < list.size(); i++) {
47
+ sum += list.get(i);
48
+ }
49
+ return sum;
50
+ }
51
+ }
API_project/Packaging_module/src/Case_package/case_demo2.java ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Case_package;
2
+
3
+ public class case_demo2 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ 自己实现parseInt方法的效果,将字符串形式的数据转成整数。
7
+ 要求:
8
+ 字符串中只能是数字,不能有其他字符
9
+ 最后一位,最多10位
10
+ 0不能开头
11
+ */
12
+
13
+ //1、定义一个字符串
14
+ String str = "123456789";
15
+ //2、校验字符串
16
+ //习惯:会先把异常数据进行过滤,剩下了就是正常的数据
17
+ if (!str.matches("[1-9]\\d{0,9}")) {
18
+ //错误的数据
19
+ System.out.println("数据格式有误");
20
+ } else {
21
+ //正确的数据
22
+ System.out.println("数据格式正确");
23
+
24
+ //3、定义一个变量表示最终的结果
25
+ int number = 0;
26
+
27
+ //4、遍历字符串得到里面的每一个字符
28
+ // 1 2 3 4
29
+ for (int i = 0; i < str.length(); i++) {
30
+ int c = str.charAt(i) - '0';
31
+ //把每一位数字放到number当中
32
+ number = number * 10 + c;
33
+ }
34
+
35
+ System.out.println(number);
36
+ }
37
+ }
38
+ }
API_project/Packaging_module/src/Case_package/case_demo3.java ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Case_package;
2
+
3
+ public class case_demo3 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ 定义一个方法自己实现toBinaryString方法的效果,将一个十进制整数转成字符串表示的二进制
7
+ */
8
+
9
+ System.out.println(toBinaryString(123));
10
+ System.out.println(Integer.toBinaryString(123));
11
+ }
12
+
13
+ public static String toBinaryString(int number) {
14
+ //核心逻辑:不断的去除以2,得到余数,一直到商为0就结束
15
+ //还需要把余数倒着拼接起来
16
+
17
+ //定义一个StringBuilder用来拼接余数
18
+ StringBuilder sb = new StringBuilder();
19
+
20
+ //利用循环不断的除以2获取余数
21
+ while (true) {
22
+ if (number == 0) {
23
+ break;
24
+ }
25
+
26
+ //获取余数 %
27
+ int remainder = number % 2;
28
+ //倒着拼接
29
+ sb.insert(0, remainder);
30
+
31
+ //除以2 /
32
+ number /= 2;
33
+ }
34
+
35
+ return sb.toString();
36
+ }
37
+ }
API_project/Packaging_module/src/Case_package/case_demo4.java ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Case_package;
2
+
3
+ import java.text.ParseException;
4
+ import java.text.SimpleDateFormat;
5
+ import java.time.LocalDate;
6
+ import java.time.LocalDateTime;
7
+ import java.time.temporal.ChronoUnit;
8
+ import java.util.Date;
9
+
10
+ public class case_demo4 {
11
+ public static void main(String[] args) throws ParseException {
12
+ //请使用代码实现计算你活了多少天,用JDK7和JDK8两种方式完成
13
+
14
+ //JDK7
15
+ //规则:只要对时间进行计算或者判断,都需要先获取当前时间的毫秒值
16
+
17
+ //1、计算出生年月日的毫秒值
18
+ String birthday = "2002年3月7日";
19
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
20
+ Date date = sdf.parse(birthday);
21
+
22
+ long birthdayTime = date.getTime();
23
+
24
+ //2、获取当前时间的毫秒值
25
+ long todayTime = System.currentTimeMillis();
26
+
27
+ //3、计算间隔了多少天
28
+ long time = todayTime - birthdayTime;
29
+ System.out.println(time / 1000 / 60 / 60 / 24);
30
+
31
+
32
+ //JDK8
33
+ LocalDate ld1 = LocalDate.of(2002, 3, 7);
34
+ LocalDate ld2 = LocalDate.now();
35
+
36
+ long days = ChronoUnit.DAYS.between(ld1, ld2);
37
+ System.out.println(days);
38
+
39
+ }
40
+ }
API_project/Packaging_module/src/Case_package/case_demo5.java ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Case_package;
2
+
3
+ import java.time.LocalDate;
4
+ import java.util.Calendar;
5
+
6
+ public class case_demo5 {
7
+ public static void main(String[] args) {
8
+ /*
9
+ 判断任意的一个年份是闰年还是平年
10
+ 要求:用JDK7和JDK8两种方式判断
11
+ 提示:
12
+ 二月有29天是闰年
13
+ 一年有366天是闰年
14
+ */
15
+
16
+ //JDK7
17
+ //我们可以把时间设置为2000年3月1日
18
+ Calendar c = Calendar.getInstance();
19
+ c.set(2002, 2, 1);//月份的范围0~11
20
+ //再把日历往前减一天
21
+ c.add(Calendar.DAY_OF_MONTH, -1);
22
+ //看当前的时间是28号还是29号?
23
+ int day = c.get(Calendar.DAY_OF_MONTH);
24
+ System.out.println(day);
25
+
26
+ //JDK8
27
+ //月份的范围:1~12
28
+ //设定时间为2002年的3月1日
29
+ LocalDate ld = LocalDate.of(2002, 3, 1);
30
+ //把时间往前减一天
31
+ LocalDate ld2 = ld.minusDays(1);
32
+ //获取这一天是一个月中的几号
33
+ int day2 = ld2.getDayOfMonth();
34
+ System.out.println(day2);
35
+ //true:闰年
36
+ //false:平年
37
+ System.out.println(ld.isLeapYear());
38
+ }
39
+ }
API_project/Packaging_module/src/Integer_package/Integer_demo1.java ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Integer_package;
2
+
3
+ public class Integer_demo1 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public Integer (int value) 根据传递的整数创建一个Integer对象
7
+ public Integer (String s) 根据传递的字符串创建一个Integer对象
8
+ public static Integer valueOf (int i) 根据传递的整数创建一个Integer对象
9
+ public static Integer valueOf (String s) 根据传递的字符串创建一个Integer对象
10
+ public static Integer valueOf (String s, int radix) 根据传递的字符串和进制创建一个Integer对象
11
+ */
12
+
13
+ //1、利用构造方法获取Integer的对象
14
+ // Integer i1 = new Integer(1);
15
+ // Integer i2 = new Integer("1");
16
+ // System.out.println(i1);
17
+ // System.out.println(i2);
18
+
19
+ //2、利用静态方法获取Integer的对象
20
+ Integer i3 = Integer.valueOf(123);
21
+ Integer i4 = Integer.valueOf("123");
22
+ Integer i5 = Integer.valueOf("123", 8);
23
+ System.out.println(i3);
24
+ System.out.println(i4);
25
+ System.out.println(i5);
26
+
27
+ //3、这两种方式获取对象的区别
28
+ //底层原理:
29
+ //因为在实际开发中,-128~127之间的数据,用的比较多
30
+ //如果每次使用都是new对象,那么太浪费内存了
31
+ //所以,提前把这个范围之内的每一个数据都创建好对象
32
+
33
+ Integer i6 = Integer.valueOf(127);
34
+ Integer i7 = Integer.valueOf(127);
35
+ System.out.println(i6 == i7);//true
36
+
37
+ Integer i8 = Integer.valueOf(128);
38
+ Integer i9 = Integer.valueOf(128);
39
+ System.out.println(i8 == i9);//false
40
+
41
+
42
+ //因为看到了new关键字,在Java中,每一次new都是创建了一个新的对象
43
+ //所以下面的两个对象都是new出来,地址值不一样
44
+ // Integer i10 = new Integer(127);
45
+ // Integer i11 = new Integer(127);
46
+ // System.out.println(i10 == i11);//false
47
+ //
48
+ // Integer i12 = new Integer(128);
49
+ // Integer i13 = new Integer(128);
50
+ // System.out.println(i12 == i13);//false
51
+ }
52
+ }
API_project/Packaging_module/src/Integer_package/Integer_demo2.java ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Integer_package;
2
+
3
+ public class Integer_demo2 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ public static String toBinaryString (int i) 得到二进制
7
+ public static String toOctalString (int i) 得到八进制
8
+ public static String toHexString (int i) 得到十六进制
9
+ public static int parseInt (String s) 将字符串类型的整数转成int类型的整数
10
+ */
11
+
12
+ //1、把整数转成二进制、十六进制
13
+ String str1 = Integer.toBinaryString(100);
14
+ System.out.println(str1);
15
+
16
+ //2、把整数转成八进制
17
+ String str2 = Integer.toOctalString(100);
18
+ System.out.println(str2);
19
+
20
+ //3、把整数转成十六进制
21
+ String str3 = Integer.toHexString(100);
22
+ System.out.println(str3);
23
+
24
+ //4、将字符串类型的整数转成int类型的整数
25
+ int i = Integer.parseInt("123");
26
+ System.out.println(i);
27
+ //细节1:
28
+ //在类型转换的时候,括号中的参数只能是数字不能是其他,否则代码会报错
29
+ //细节2:
30
+ //8种包装类当中,除了Character都有对应的parseXxx的方法,进行类型转换
31
+ String s = "true";
32
+ boolean b = Boolean.parseBoolean(s);
33
+ System.out.println(b);
34
+ }
35
+ }
API_project/Packaging_module/src/Integer_package/Integer_demo3.java ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Integer_package;
2
+
3
+ import java.util.Scanner;
4
+
5
+ public class Integer_demo3 {
6
+ public static void main(String[] args) {
7
+ //键盘录入
8
+ Scanner sc = new Scanner(System.in);
9
+ System.out.println("请输入一个字符串:");
10
+
11
+ //弊端:
12
+ //当我们在使用next,nextInt,nextDouble在接收数据的时候,遇到空格,回车,制表符的时候就停止了
13
+ //键盘录入的是123 123 那么此时只能接收到空格前面的数据
14
+ //我想要的是接收一整行数据
15
+ //约定:
16
+ //以后我们想要键盘录入,不管什么类型,统一使用nextLine
17
+ //特点遇到回车才停止
18
+
19
+ String line = sc.nextLine();
20
+ System.out.println(line);
21
+
22
+ double v = Double.parseDouble(line);
23
+ System.out.println(v);
24
+
25
+ }
26
+ }
API_project/Regular_expression_module/Regular_expression_module.iml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
API_project/Regular_expression_module/src/Regular_expression_Case_package/Regex_demo1.java ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Regular_expression_Case_package;
2
+
3
+ import javax.xml.transform.Source;
4
+
5
+ public class Regex_demo1 {
6
+ public static void main(String[] args) {
7
+ /*
8
+ 需求:
9
+ 请编写正则表达式验证用户输入的手机号码是否满足要求。
10
+ 请编写正则表达式验证用户输入的邮箱号是否满足要求。
11
+ 请编写正则表达式验证用户输入的电话号码是否满足要求。
12
+
13
+ 验证手机号码 13112345678 13712345667 13945679027 139456790271
14
+ 验证座机电话号码 020-2324242 02122442 027-42424 0712-3242434
15
+ 验证邮箱号码 3232323@qq.com zhangsan@itcast.cnn dlei0009@163.com dlei0009@pci.com.cn
16
+ */
17
+
18
+ //心得:
19
+ //拿着一个正确的数据,从左到右依次去写
20
+ //13112345678
21
+ //分成三部分:
22
+ //第一部分:1 表示手机号码只能以1开头
23
+ //第二部分:[3-9] 表示手机号码第二位只能是3-9之间的
24
+ //第三部分:\\d{9} 表示任意数字可以出现9次,也只能出现9次
25
+ String regex1 = "1[3-9]\\d{9}";
26
+ System.out.println("13112345678".matches(regex1));
27
+ System.out.println("13712345667".matches(regex1));
28
+ System.out.println("13945679027".matches(regex1));
29
+ System.out.println("139456790271".matches(regex1));
30
+
31
+
32
+ //座机电话号码
33
+ //020-2324242 02122442 027-42424 0712-3242434
34
+ //思路:
35
+ //在书写座机号正则的时候需要把正确的数据分为三部分
36
+ //一:区号 0\\d{2,3}
37
+ // 0:表示区号一定是以0开头的
38
+ // \\d{2,3}:表示区号从第二位开始可以是任意的数字,可以出现2到3次
39
+ //二:- ?表示次数,0次或1次
40
+ //三:号码 号码的第一位也不能以0开头,从第二位开始可以是任意的数字,号码的总长度:5-10
41
+ String regex2 = "0\\d{2,3}-?[1-9]\\d{4,9}";
42
+ System.out.println("020-2324242".matches(regex2));
43
+ System.out.println("02122442".matches(regex2));
44
+ System.out.println("027-42424".matches(regex2));
45
+ System.out.println("0712-3242434".matches(regex2));
46
+
47
+
48
+ //邮箱号码
49
+ //3232323@qq.com zhangsan@itcast.cnn dlei0009@163.com dlei0009@pci.com.cn
50
+ //思路:
51
+ //在书写邮箱号码正则的时候需要把正确的数据分为三部分
52
+ //第一部分:@的左边
53
+ // \\w+ 任意的字母数字下划线,至少出现一次就可以了
54
+ //第二部分:@ 只能出现一次
55
+ //第三部分:
56
+ // 3.1 .的左边 [\\w&&[^_]]{2,6}
57
+ // 任意的字母加数字,总共出现2-6次(此时不能出现下划线)
58
+ // 3.2 . \\.
59
+ // 3.3 大写字母,小写字母都可以,只能出现2-3次 [a-zA-Z]{2,3}
60
+ // 我们可以把3.2和3.3看成一组,这一组可以出现1次或者2次
61
+ String regex3 = "\\w+@[\\w&&[^_]]{2,6}(\\.[a-zA-Z]{2,3}){1,2}";
62
+ System.out.println("3232323@qq.com".matches(regex3));
63
+ System.out.println("zhangsan@itcast.cnn".matches(regex3));
64
+ System.out.println("dlei0009@163.com".matches(regex3));
65
+ System.out.println("dlei0009@pci.com.cn".matches(regex3));
66
+
67
+
68
+ //24小时的正则表达式
69
+ String regex4 = "([01]\\d|2[0-3])(:[0-5]\\d){2}";
70
+ System.out.println("23:11:11".matches(regex4));
71
+ }
72
+ }
API_project/Regular_expression_module/src/Regular_expression_Case_package/Regex_demo2.java ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Regular_expression_Case_package;
2
+
3
+ public class Regex_demo2 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ 需求:
7
+ 请编写正则表达式验证用户名是否满足要求。
8
+ 要求:大小写字母,数字,下划线一共4-16位
9
+ 请编写正则表达式验证身份证号码是否满足要求。
10
+ 简单要求:18位,前17位任意数字,最后一位可以是数字可以是大写或小写的x
11
+ 复杂要求:按照身份证号码的格式
12
+
13
+ 身份证号码:
14
+ 吴海港 14042419861123283X
15
+ 汪少明 350122198009090517
16
+ 黄陈晓 331023199303277190
17
+ 邝建鸿 370103199302090953
18
+ */
19
+
20
+ //用户名要求:大小写字母,数字,下划线一共4-16位 [a-zA-Z0-9_]
21
+ String regex1 = "\\w{4,16}";
22
+ System.out.println("zhangsan".matches(regex1));
23
+ System.out.println("$1234".matches(regex1));
24
+
25
+ //身份证号码的简单校验:
26
+ //18位,前17位任意数字,最后一位可以是数字可以是大写或小写的x
27
+ String regex2 = "[1-9]\\d{16}(\\d|X|x)";
28
+ System.out.println("14042419861123283X".matches(regex2));
29
+ System.out.println("350122198009090517".matches(regex2));
30
+ System.out.println("331023199303277190".matches(regex2));
31
+ System.out.println("370103199302090953".matches(regex2));
32
+
33
+
34
+ //忽略大小写的书写方式
35
+ //在匹配的时候忽略bc的大小写
36
+ String regex4 = "a(?i)bc";
37
+ System.out.println("----------------------");
38
+ System.out.println("abc".matches(regex4));
39
+ System.out.println("ABC".matches(regex4));
40
+ System.out.println("aBC".matches(regex4));
41
+
42
+
43
+ //身份证号码的严格校验
44
+ //编写正则的小心得:
45
+ //第一步:按照正确的数据进行拆分
46
+ //第二步:找每一部分的规律,并编写正则表达式
47
+ //第三步:把每一部分的正则拼接在一起,就是最终的结果
48
+ //书写的时候:从左到右去书写
49
+
50
+
51
+ //14042419861123283X
52
+ //前面6位:省份,市区,派出所等信息 第一位不能是0,后面5位是任意数字 [1-9]\\d{5}
53
+ //年的前半段:18 19 20 (18|19|20)
54
+ //年的后半段:任意数字出现两次 \\d{2}
55
+ //月份: 12个月 0[1-9]|1[0-2]
56
+ //日期: 1~31 0[1-9]|[12]\\d|3[01]
57
+ //后面四位:任意数字出现3次,最后一位可以是数字也可以是大写X或者小写x \\d{3}[\\dXx]
58
+ String regex5 = "[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]";
59
+ System.out.println("----------------------");
60
+ System.out.println("14042419861123283X".matches(regex5));
61
+ System.out.println("350122198009090517".matches(regex5));
62
+ System.out.println("331023199303277190".matches(regex5));
63
+ System.out.println("370103199302090953".matches(regex5));
64
+ }
65
+ }
API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo1.java ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Regular_expression_package;
2
+
3
+ public class Regex_demo1 {
4
+ public static void main(String[] args) {
5
+ /*
6
+ 假如现在要求校验一个QQ号码是否正确,
7
+ 规则:6位及20位之内,0不能在开头,必须全部是数字。
8
+ 先使用目前所学知识完成校验需求
9
+ 然后体验一下正则表达式检验
10
+ */
11
+
12
+ String qq = "1234567890";
13
+ System.out.println(checkQQ(qq));
14
+
15
+ System.out.println(qq.matches("[1-9]\\d{5,19}"));
16
+
17
+ }
18
+
19
+ public static boolean checkQQ(String qq) {
20
+ //规则:6位及20位之内,0不能在开头,必须全部是数字
21
+ //核心思想:
22
+ //先把异常数据进行过滤
23
+ //下面的就是满足要求的数据了
24
+ int len = qq.length();
25
+
26
+ if ((len < 6) || (len > 20)) {
27
+ return false;
28
+ }
29
+
30
+ //0不能在开头
31
+ if (qq.startsWith("0")) {
32
+ return false;
33
+ }
34
+
35
+ //必须全部是数字
36
+ for (int i = 0; i < qq.length(); i++) {
37
+ char c = qq.charAt(i);
38
+ if (c < '0' || c > '9'){
39
+ return false;
40
+ }
41
+ }
42
+
43
+ return true;
44
+
45
+ }
46
+ }
API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo2.java ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Regular_expression_package;
2
+
3
+ public class Regex_demo2 {
4
+ public static void main(String[] args) {
5
+ //public boolean matches (String regex):判断是否与正则表达式匹配,匹配返回true
6
+
7
+ //只能是 a b c
8
+ System.out.println("------------1-------------");
9
+ System.out.println("a".matches("[abc]")); //true
10
+ System.out.println("z".matches("[abc]")); //false
11
+ System.out.println("ab".matches("[abc]")); //false
12
+ System.out.println("ab".matches("[abc][abc]")); //true
13
+
14
+ //不能出现 a b c
15
+ System.out.println("------------2-------------");
16
+ System.out.println("a".matches("[^abc]")); // false
17
+ System.out.println("z".matches("[^abc]")); // true
18
+ System.out.println("zz".matches("[^abc]")); // false
19
+ System.out.println("zz".matches("[^abc][^abc]")); //true
20
+
21
+
22
+ // a到z A到Z (包含头尾范围)
23
+ System.out.println("------------3-------------");
24
+ System.out.println("a".matches("[a-zA-Z]")); // true
25
+ System.out.println("z".matches("[a-zA-Z]")); // true
26
+ System.out.println("aa".matches("[a-zA-Z]")); // false
27
+ System.out.println("zz".matches("[a-zA-Z]")); // false
28
+ System.out.println("zz".matches("[a-zA-Z][a-zA-Z]")); // true
29
+ System.out.println("0".matches("[a-zA-Z]")); // false
30
+ System.out.println("0".matches("[a-zA-Z0-9]")); // true
31
+
32
+
33
+ //[a-d[m-p]] a到d,或m到p
34
+ System.out.println("------------4-------------");
35
+ System.out.println("a".matches("[a-d[m-p]]"));//true
36
+ System.out.println("d".matches("[a-d[m-p]]"));//true
37
+ System.out.println("m".matches("[a-d[m-p]]"));//true
38
+ System.out.println("p".matches("[a-d[m-p]]"));//true
39
+ System.out.println("e".matches("[a-d[m-p]]"));//false
40
+ System.out.println("0".matches("[a-d[m-p]]"));//false
41
+
42
+
43
+ //[a-z&&[def]] a-z和def的交集,为:d,e,f
44
+ //细节:如果要求两个范围的交集,那么需要写符号 &&
45
+ //如果写成&,那么此时&表示就不是交集了,而是一个简简单单的&符号
46
+ System.out.println("------------5-------------");
47
+ System.out.println("a".matches("[a-z&[def]]")); //true
48
+ System.out.println("&".matches("[a-z&[def]]")); //true
49
+ System.out.println("d".matches("[a-z&&[def]]")); //true
50
+ System.out.println("0".matches("[a-z&&[def]]")); //false
51
+
52
+
53
+ //[a-z&&[^bc]] a-z和非bc的交集
54
+ System.out.println("------------6-------------");
55
+ System.out.println("a".matches("[a-z&&[^bc]]")); //true
56
+ System.out.println("b".matches("[a-z&&[^bc]]")); //false
57
+ System.out.println("0".matches("[a-z&&[^bc]]")); //false
58
+
59
+
60
+ //[a-z&&[^m-p]] a-z和除m-p的交集
61
+ System.out.println("------------7-------------");
62
+ System.out.println("a".matches("[a-z&&[^m-p]]")); //true
63
+ System.out.println("m".matches("[a-z&&[^m-p]]")); //false
64
+ System.out.println("0".matches("[a-z&&[^m-p]]")); //false
65
+
66
+
67
+ }
68
+ }
API_project/Regular_expression_module/src/Regular_expression_package/Regex_demo3.java ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Regular_expression_package;
2
+
3
+ public class Regex_demo3 {
4
+ public static void main(String[] args) {
5
+ // \ 转义字符 改变后面那个字符原本的含义
6
+ //练习:以字符串的形式打印一个双引号
7
+ //" 在Java中表示字符串的开头或者结尾
8
+
9
+ //此时\表示转义字符,改变了后面那个双引号原本的含义
10
+ //把其变成了一个普普通通的双引号而已
11
+ System.out.println("\"\"");
12
+
13
+ // \\前面的\是一个转义字符,改变了后面\原本的含义,把他变成一个普普通通的\而已
14
+ System.out.println("\\");
15
+
16
+
17
+ // .表示任意字符
18
+ System.out.println("你".matches("..")); //false
19
+ System.out.println("你a".matches("..")); //true
20
+
21
+
22
+ // \\d只能是任意的一位数字
23
+ // 简单来记:两个\表示一个\
24
+ System.out.println("a".matches("\\d")); //false
25
+ System.out.println("3".matches("\\d")); //true
26
+ System.out.println("333".matches("\\d")); //false
27
+
28
+
29
+ // \\w只能是一位单词字符 [a-zA-Z_0-9]
30
+ System.out.println("z".matches("\\w")); //true
31
+ System.out.println("2".matches("\\w")); //true
32
+ System.out.println("21".matches("\\w")); //false
33
+ System.out.println("你".matches("\\w")); //false
34
+
35
+
36
+ //非单词字符
37
+ System.out.println("你".matches("\\W")); //true
38
+ System.out.println("--------------------");
39
+ //以上正则匹配只能校验单个字符
40
+
41
+
42
+ //必须是数字 字母 下划线 至少6位
43
+ System.out.println("2442fsfsf".matches("\\w{6,}")); //true
44
+ System.out.println("244f".matches("\\w{6,}")); //false
45
+
46
+
47
+ //必须是数字和字符 必须是4位
48
+ System.out.println("23dF".matches("[a-zA-Z0-9]{4}"));//true
49
+ System.out.println("23_F".matches("[a-zA-Z0-9]{4}"));//false
50
+ System.out.println("23dF".matches("[\\w&&[^_]]{4}"));//true
51
+ System.out.println("23_F".matches("[\\w&&[^_]]{4}"));//false
52
+ }
53
+ }