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

相关推荐

点赞 评论 收藏
分享
10-09 09:39
门头沟学院 C++
HHHHaos:这也太虚了,工资就一半是真的
点赞 评论 收藏
分享
牛客网
牛客企业服务