private static void Demo3() {         Stack<Character> st1=new Stack();         System.out.println("请输入一行字符串:");         Scanner sc1= new Scanner(System.in);         String str = sc1.nextLine(); //        System.err.println(str);         for (int i = 0; i < str.length(); i++) {             char ch=str.charAt(i);             switch(ch) {                 case '{':                 case '[':                 case '(':                     st1.push(ch);                     break;                 case '}':                 case ']':                 case ')':                     if (!st1.isEmpty()) {                         char chx=st1.pop();                         if ((ch=='{'&&chx!='}')||(ch=='['&&chx!=']')||(ch=='('&&chx!=')')) {                             System.out.println("Error" + ch+i);                         }                     }  else {                         System.out.println("Error" + ch+i);                         }                     break;                     default:  break;             }         }         if (!st1.isEmpty()) {             System.out.println("Error" +st1.pop());         } //        while (!st1.isEmpty()) { //            System.out.println(st1.pop()); //        }     } 大佬NB
点赞 2

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务