import java.util.regex.*;

class Uni {
	public static boolean isProperlyNested(String toTest) {
	    int countOpen = 0;
	    for (char c : toTest.toCharArray()) {
	        if (c == '{') {
	            countOpen++;
	        } else if (c == '}') {
	            countOpen--;
	            if (countOpen < 0) return false;
	        }
	    }
	    return countOpen == 0;
	}
	public static void main (String[] args) {
        String str1 = "{} {\n" +
                      "    {} {}\n" +
                      "} // Properly nested",
               str2 = "{{\n" +
                      "    {{}}\n" +
                      "} {} // Not properly nested";
        System.out.println(str1 + "\t" + isProperlyNested(str1));
        System.out.println(str2 + "\t" + isProperlyNested(str2));
    }
}