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

相关推荐

11-03 18:50
门头沟学院 Java
安远迢迢:问就是半年
点赞 评论 收藏
分享
牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务