commit 945b9abe62857e502cbdb55114358849ad93605e Author: hewh Date: Tue Mar 31 10:15:37 2026 +0800 第一次作业 diff --git a/demo/pom.xml b/demo/pom.xml new file mode 100644 index 0000000..dfa2fdc --- /dev/null +++ b/demo/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.example + demo + 1.0-SNAPSHOT + + + 17 + 17 + + + + + + com.alibaba + fastjson + 1.2.83 + + + + + \ No newline at end of file diff --git a/demo/src/main/java/com/example/Main.java b/demo/src/main/java/com/example/Main.java new file mode 100644 index 0000000..dabe3f8 --- /dev/null +++ b/demo/src/main/java/com/example/Main.java @@ -0,0 +1,23 @@ +package com.example; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } + + // 给整数数组排序的函数(升序排序) + public static void sortArray(int[] arr) { + for (int i = 0; i < arr.length - 1; i++) { + for (int j = i + 1; j < arr.length; j++) { + if (arr[j] < arr[i]) { + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + } + } + + + +} \ No newline at end of file diff --git a/demo/src/main/java/com/example/Person.java b/demo/src/main/java/com/example/Person.java new file mode 100644 index 0000000..8d08a7f --- /dev/null +++ b/demo/src/main/java/com/example/Person.java @@ -0,0 +1,30 @@ +package com.example; + +public class Person { + public String name; + public int age; + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public static void main(String[] args) { + Person [] people; + people = new Person[2]; + int number = 2; + for(int i = 0; i < number; i++) { + people[i] = new Person("Person" + i, 20 + i); + } + for(int i = 0; i < number; i++) { + people[i].sayHello(); + } + } + + public void sayHello() { + int age = this.age; + int birthYear = 2026 - age; + System.out.println("Hello, my name is " + name + " and I was born in " + birthYear + "."); + } + +} \ No newline at end of file diff --git a/demo/src/main/java/com/example/Test.java b/demo/src/main/java/com/example/Test.java new file mode 100644 index 0000000..767b07d --- /dev/null +++ b/demo/src/main/java/com/example/Test.java @@ -0,0 +1,52 @@ +import java.util.regex.Pattern; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + + +public class Test { + + + private static String regex = "[!@#$%^&*(),.?\":{}|<>。,!;;]"; + private static Pattern pattern = Pattern.compile(regex); + + public static void main(String[] args) { + String source = "{\"1\":\"第一条\",\"2\":\"第二条\",\"3\":\"第三条\"}"; + String s = toStringArray(source); + System.out.println(s); + } + + /** + * 数组格式字符串转 String 数组 + * + * @param source + * @return + */ + public static String toStringArray(String source) { + + + JSONObject json = JSONObject.parseObject(source); + StringBuilder str = new StringBuilder(); + int i = 1; + for (String key : json.keySet()) { + String s = json.getString(key); + String substring = s.substring(s.length() - 1); + Matcher matcher = pattern.matcher(substring); + s = matcher.find() ? s.substring(0, s.length() - 1) + "。" : s + "。"; + str.append(" ").append(i).append(":").append(s).append("\r\n"); + i++; + } + +// String[] split = source.substring(1, source.length() - 1).replace("\"", "").split(","); +// StringBuilder str = new StringBuilder(); +// int i = 1; +// for (String s : jsonList) { +// String substring = s.substring(s.length() - 1); +// Matcher matcher = pattern.matcher(substring); +// s = matcher.find() ? s.substring(0, s.length() - 1) + "。" : s + "。"; +// str.append(" ").append(i).append(":").append(s).append("\r\n"); +// i++; +// } + return str.toString(); + } + +} diff --git a/demo/target/classes/com/example/Main.class b/demo/target/classes/com/example/Main.class new file mode 100644 index 0000000..6f08c10 Binary files /dev/null and b/demo/target/classes/com/example/Main.class differ diff --git a/demo/target/classes/com/example/Person.class b/demo/target/classes/com/example/Person.class new file mode 100644 index 0000000..dfecd5a Binary files /dev/null and b/demo/target/classes/com/example/Person.class differ diff --git a/demo/target/classes/com/example/Test.class b/demo/target/classes/com/example/Test.class new file mode 100644 index 0000000..4cb2964 Binary files /dev/null and b/demo/target/classes/com/example/Test.class differ diff --git a/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..1a8f6b8 --- /dev/null +++ b/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +k:\java\demo\demo\src\main\java\com\example\Main.java +k:\java\demo\demo\src\main\java\com\example\Test.java