@@ -0,0 +1,2828 @@
+package java_problems.data_structures;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement:%0D%0A * A string containing only parentheses is balanced if the following is true:%0D%0A * %0D%0A * if it is an empty string%0D%0A * if A and B are correct, AB is correct,%0D%0A * if A is correct, (A) and %7BA%7D and %5BA%5D are also correct.%0D%0A * Examples of some correctly balanced strings are: %22%7B%7D()%22, %22%5B%7B()%7D%5D%22, %22(%7B()%7D)%22%0D%0A * Examples of some unbalanced strings are: %22%7B%7D(%22, %22(%7B)%7D%22, %22%5B%5B%22, %22%7D%7B%22 etc.%0D%0A * Given a string, determine if it is balanced or not.%0D%0A * %0D%0A * Input Format:%0D%0A * There will be multiple lines in the input file, each having a single%0D%0A * non-empty string. You should read input till end-of-file.%0D%0A * The part of the code that handles input operation is already provided in the%0D%0A * editor.%0D%0A * %0D%0A * Output Format:%0D%0A * For each case, print 'true' if the string is balanced, 'false' otherwise.%0D%0A * %0D%0A * Sample Input:%0D%0A * %7B%7D()%0D%0A * (%7B()%7D)%0D%0A * %7B%7D(%0D%0A * %5B%5D%0D%0A * %0D%0A * Sample Output:%0D%0A * true%0D%0A * true%0D%0A * false%0D%0A * true%0D%0A */%0D%0Apublic class JavaStack %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09   %0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        int countLeftCurly;%0D%0A        int countLeftParen;%0D%0A        int countLeftBracket;%0D%0A        int countRightCurly;%0D%0A        int countRightParen;%0D%0A        int countRightBracket;  %0D%0A       %0D%0A        while (sc.hasNext()) %7B%0D%0A            String input=sc.next();%0D%0A            countLeftCurly = 0;%0D%0A            countLeftParen = 0;%0D%0A            countLeftBracket = 0;%0D%0A            countRightCurly = 0;%0D%0A            countRightParen = 0;%0D%0A            countRightBracket = 0;%0D%0A            for (int i = 0; i %3C input.length(); i++) %7B%0D%0A                char next = input.charAt(i);%0D%0A                switch (next) %7B%0D%0A                    case '(':%0D%0A                        countLeftParen++;%0D%0A                        break;%0D%0A                    case '%7B':%0D%0A                        countLeftCurly++;%0D%0A                        break;%0D%0A                    case '%5B':%0D%0A                        countLeftBracket++;%0D%0A                        break;%0D%0A                    case ')':%0D%0A                        countRightParen++;%0D%0A                        break;%0D%0A                    case '%7D':%0D%0A                        countRightCurly++;%0D%0A                        break;%0D%0A                    case '%5D':%0D%0A                        countRightBracket++;%0D%0A                        break;%0D%0A                    default:%0D%0A                        System.out.println(%22Unexpected character %22 + next + %22.%22);%0D%0A                %7D%0D%0A            %7D%0D%0A            if (countLeftParen == countRightParen && countLeftCurly == countRightCurly &&%0D%0A                countLeftBracket == countRightBracket) %7B%0D%0A                System.out.println(%22true%22);%0D%0A            %7D else %7B%0D%0A                System.out.println(%22false%22);%0D%0A            %7D%0D%0A        %7D%0D%0A        sc.close();%0D%0A    %7D%0D%0A%7D

Add JavaStack