Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  CandidateCode.java
Language: JAVA
Code:
import java.util.*;

public class CandidateCode
{
    public static String validString(String input1)
    {
    Hashtable<Character ,Character> closeTable = new Hashtable <Character ,Character>();
     closeTable.put ('(',')');
     closeTable.put ('{','}');
     closeTable.put ('[',']');

     ArrayList<Character> stack = new ArrayList<Character>();

     for(int i=0 ; i < input1.length() ; i++)
     {
         Character c =input1.charAt(i);

         if(stack.size() > 0 && closeTable.get(stack.get(0))== c)
         {
           stack.remove(0);
         }
         else
         {
           stack.add(0,c);
         }
     }

       String output =stack.size() ==  0 ? "Correct" : "Incorrect" ;

       return output ;
    }

    public static void main(String args[])
    {
          CandidateCode test = new CandidateCode();

          test.validString("({}[((({{}})[{()}]))])");
     }
}     
Comments: