public static boolean checkForm(String str){
  int openParentheses=0;
  int openBrackets=0;
  int openBraces=0;
  for (int i=0; i < str.length(); i++) {
    char c=str.charAt(i);
switch (c) {
case '(':
      openParentheses++;
    break;
case ')':
  openParentheses--;
if (openParentheses < 0) return false;
break;
case '[':
openBrackets++;
break;
case ']':
openBrackets--;
if (openBrackets < 0) return false;
break;
case '{':
openBraces++;
break;
case '}':
openBraces--;
if (openBraces < 0) return false;
break;
}
}
boolean balanced=(openParentheses == 0 && openBrackets == 0 && openBraces == 0);
return balanced;
}

public static boolean checkForm ( String str ) { int openParentheses = 0 ; int openBrackets = 0 ; int openBraces = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char c = str . charAt ( i ) ; switch ( c ) { case '(' : openParentheses ++ ; break ; case ')' : openParentheses -- ; if ( openParentheses < 0 ) return false ; break ; case '[' : openBrackets ++ ; break ; case ']' : openBrackets -- ; if ( openBrackets < 0 ) return false ; break ; case '{' : openBraces ++ ; break ; case '}' : openBraces -- ; if ( openBraces < 0 ) return false ; break ; } } boolean balanced = ( openParentheses == 0 && openBrackets == 0 && openBraces == 0 ) ; return balanced ; }
checks the form of the string to ensure that all parentheses , braces and brackets are balanced . logs warning messages if problems are detected .
