commit
945b9abe62
9 changed files with 133 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<groupId>com.example</groupId> |
||||
|
<artifactId>demo</artifactId> |
||||
|
<version>1.0-SNAPSHOT</version> |
||||
|
|
||||
|
<properties> |
||||
|
<maven.compiler.source>17</maven.compiler.source> |
||||
|
<maven.compiler.target>17</maven.compiler.target> |
||||
|
</properties> |
||||
|
|
||||
|
<dependencies> |
||||
|
<!-- 其他依赖项 --> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba</groupId> |
||||
|
<artifactId>fastjson</artifactId> |
||||
|
<version>1.2.83</version> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
|
||||
|
|
||||
|
</project> |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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 + "."); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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 |
||||
Loading…
Reference in new issue