delimitermatch.java~14~

来自「符号匹配」· JAVA~14~ 代码 · 共 49 行

JAVA~14~
49
字号
import java.io.*;
import java.util.*;
public class DelimiterMatch {
    Stack stack = new Stack();
    public void Matching()throws IOException{
        String s = " ";char temp,next;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            s = br.readLine();
        }catch(IOException e){
        }
        for(int i=0;i<s.length();i++){
            temp=s.charAt(i);
            if(temp =='('||temp == '['){
                stack.push(i);
                stack.push(temp);
            }
            if(temp == ')'&&stack.isEmpty())
                System.out.println("不匹配信息为:  ) in colum "+i+" is not matching");
            if(temp == ']'&&stack.isEmpty())
                System.out.println("不匹配信息为:  ] in colum "+i+" is not matching");
            if(temp == ')'&&!stack.isEmpty()){
                next = (Character) stack.pop();
                int m = (Integer) stack.pop();
                if(next == '(')continue;
                //else if(stack.isEmpty())
                 // System.out.println("不匹配信息为:  ) in colum "+i+" is not matching");
                else
                System.out.println("不匹配信息为: "+next+" in colum "+ m +" is not matching with ) in colum "+i);
            }
            if(temp == ']'&&!stack.isEmpty()){
                next = (Character) stack.pop();
                int m = (Integer) stack.pop();
                if(next == '[')continue;
               // else if(stack.isEmpty())
                //  System.out.println("不匹配信息为:  ] in colum "+i+" is not matching");
                else
                System.out.println("不匹配信息为: "+next+" in colum "+ m +" is not matching with ] in colum "+i);
            }
            else if(temp!='('&& temp!='[')
             continue;
        }
        }
    public static void main(String[] args)throws IOException {
        DelimiterMatch delimitermatch = new DelimiterMatch();
        delimitermatch.Matching();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?