How to check if a String is balanced?

前端 未结 8 1063
逝去的感伤
逝去的感伤 2020-12-06 11:57

I want to test if an input String is balanced. It would be balanced if there is a matching opening and closing parenthesis, bracket or brace.

example:
{} bal         


        
8条回答
  •  孤城傲影
    2020-12-06 12:37

    import java.util.*;
    public class Parenthesis
    {
        public static void main (String ...argd)
        {
            Scanner sc=new Scanner(System.in);
            System.out.println("enetr string");
            String s=sc.nextLine();
            Stack st=new Stack();  
            for (int i=0;i

提交回复
热议问题