stack = new Stack<>();
+
+ //如果字符串长度不是偶数,则一定无法匹配。返回false
+ if (s.length() % 2 != 0) {
+ return false;
+ } else { //如果字符串长度是偶数,可能存在true,继续
+ for (char item : s.toCharArray()) { //把输入的字符串变成字符数组,使用item遍历
+ if (item == '(' || item == '[' || item == '{') { //如果遍历到的是左括号,则进栈,继续下一轮循环
+ stack.push(item);
+ } else if (item == ')' || item == ']' || item == '}') { //如果遍历到的是右括号,可能涉及到出栈
+ if (stack.isEmpty()) { //如果当前栈是空的,无法出栈。但是现在匹配到了右括号但没有左括号,说明匹配失败
+ return false;
+ } else { //如果当前栈不为空
+ char jtem = stack.pop(); //出栈,把栈顶元素赋值给jtem
+ if ((jtem == '(' && item == ')') || (jtem == '[' && item == ']') || (jtem == '{' && item == '}')) { //如果可以匹配成功,则继续下一轮循环
+ continue;
+ } else { // 当前栈不空,且item与jtem无法匹配,说明匹配失败
+ return false;
+ }
+ }
+ }
+ }
+ if (!stack.isEmpty()) { //如果遍历完字符数组以后栈不是空的,说明有多余的左括号,失败
+ return false;
+ } else { //遍历完数组不为空,成功
+ return true;
+ }
+ }
+ }
+
+ public static void main(String [] args){
+ junit_y y = new junit_y();
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("请输入需要判断是否匹配的字符串的值");
+ String s = scanner.next();
+ System.out.println("结果为:"+y.kuohao(s));
+
+
+ }
+
+}
+
+
diff --git a/TomcatTest_0415/src/main/java/com/maven/tomcattest_0415/HelloServlet.java b/TomcatTest_0415/src/main/java/com/maven/tomcattest_0415/HelloServlet.java
new file mode 100644
index 0000000..1920296
--- /dev/null
+++ b/TomcatTest_0415/src/main/java/com/maven/tomcattest_0415/HelloServlet.java
@@ -0,0 +1,27 @@
+package com.maven.tomcattest_0415;
+
+import java.io.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.*;
+
+@WebServlet(name = "helloServlet", value = "/hello-servlet")
+public class HelloServlet extends HttpServlet {
+ private String message;
+
+ public void init() {
+ message = "Hello World!";
+ }
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.setContentType("text/html");
+
+ // Hello
+ PrintWriter out = response.getWriter();
+ out.println("");
+ out.println("" + message + "
");
+ out.println("");
+ }
+
+ public void destroy() {
+ }
+}
\ No newline at end of file
diff --git a/TomcatTest_0415/src/main/webapp/WEB-INF/web.xml b/TomcatTest_0415/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d80081d
--- /dev/null
+++ b/TomcatTest_0415/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,6 @@
+
+
+
\ No newline at end of file
diff --git a/TomcatTest_0415/src/main/webapp/index.jsp b/TomcatTest_0415/src/main/webapp/index.jsp
new file mode 100644
index 0000000..f7eba3c
--- /dev/null
+++ b/TomcatTest_0415/src/main/webapp/index.jsp
@@ -0,0 +1,14 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+
+
+
+ JSP - Hello World
+
+
+<%= "Hello World!" %>
+
+add something for homework which named git
+
+Hello Servlet
+
+
\ No newline at end of file
diff --git a/TomcatTest_0415/src/test/java/com/junit/junit_yTest.java b/TomcatTest_0415/src/test/java/com/junit/junit_yTest.java
new file mode 100644
index 0000000..52a43f2
--- /dev/null
+++ b/TomcatTest_0415/src/test/java/com/junit/junit_yTest.java
@@ -0,0 +1,29 @@
+package com.junit;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author YangJinwen
+ */
+class junit_yTest {
+ @Test
+ public void kuohao_tiaojian() {
+ junit_y y = new junit_y();
+ //测试长度不是偶数的情况
+ assertFalse(y.kuohao("("));
+
+
+ //测试长度是偶数的情况
+ //测试当前遍历右括号但栈空的情况
+ assertFalse(y.kuohao("()))"));
+ //测试当前遍历右括号,栈不空,无法匹配的情况
+ assertFalse(y.kuohao("{())"));
+ //测试遍历完数组以后栈不空的情况
+ assertFalse(y.kuohao("(("));
+
+ //测试所有条件都为真的情况
+ assertTrue(y.kuohao("()[]{}"));
+ }
+}
\ No newline at end of file
diff --git a/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/META-INF/MANIFEST.MF b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..153e08e
--- /dev/null
+++ b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Created-By: IntelliJ IDEA
+Built-By: YangJinwen
+Build-Jdk: Oracle OpenJDK version 19.0.2
+
diff --git a/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/WEB-INF/web.xml b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/WEB-INF/web.xml
new file mode 100644
index 0000000..d80081d
--- /dev/null
+++ b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/WEB-INF/web.xml
@@ -0,0 +1,6 @@
+
+
+
\ No newline at end of file
diff --git a/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/index.jsp b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/index.jsp
new file mode 100644
index 0000000..e739f74
--- /dev/null
+++ b/TomcatTest_0415/target/TomcatTest_0415-1.0-SNAPSHOT/index.jsp
@@ -0,0 +1,16 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+
+
+
+ JSP - Hello World
+
+
+<%= "Hello World!" %>
+
+add something for homework which named git
+gghtrsgnjurgnjvgrne
+,vljfgihaglajl
+
+Hello Servlet
+
+
\ No newline at end of file
--
Gitee
From b45444a8ae4c7d22eb95920bd230101e6cdd951a Mon Sep 17 00:00:00 2001
From: Yang <3251918330@qq.com>
Date: Tue, 16 Apr 2024 16:12:54 +0800
Subject: [PATCH 6/8] change index.jsp
---
TomcatTest_0415/src/main/webapp/index.jsp | 1 +
1 file changed, 1 insertion(+)
diff --git a/TomcatTest_0415/src/main/webapp/index.jsp b/TomcatTest_0415/src/main/webapp/index.jsp
index f7eba3c..3db4dc0 100644
--- a/TomcatTest_0415/src/main/webapp/index.jsp
+++ b/TomcatTest_0415/src/main/webapp/index.jsp
@@ -10,5 +10,6 @@
add something for homework which named git
Hello Servlet
+change for homework named git