public class ExprChecker { // we need a stack public static final int MAX=100; public static String[] stackContent = new String[MAX]; public static int size = 0; public static void push(String str){ stackContent[size] = str; size = size + 1; } public static String pop(){ size = size - 1; return stackContent[size]; } public static boolean isEmpty(){ //return (size == 0); if(size == 0) return true; else return false; } public static void main(String[] args) { boolean wellFormed = true; for(int i=0; i < args.length; i++){ if(isOpening(args[i])){ push(args[i]); }else{ if(isEmpty()){ wellFormed = false; }else{ String prev = pop(); if(!match(args[i], prev)){ wellFormed = false; } } } } if(isEmpty()){ wellFormed = false; } System.out.println("You entered: "); for(int i=0; i < args.length; i++){ System.out.print(args[i] + " "); } System.out.println(); if(wellFormed){ System.out.println(": )"); } else{ System.out.println(":("); } } }