Question: 2. Consider the language L wSw': w is a possibly empty string of characters other than S w, = reverse(w)) For example abcScba is a


2. Consider the language L wSw': w is a possibly empty string of characters other than S w, = reverse(w)) For example "abcScba" is a string of that language. "abcScbd" is not. Write a Java recognition method for this language that uses both a queue and a stack. Thus, as you traverse the input string, you insert each character of w into a queue and each character of w into a stack. Assume that each input string contains exactly one $. Use JCF's implementations of the queue and the stack. Name your method isInLanguage. Have your method display a message whether or not the string is in the language. For example: If the entered word is abc$cbd , the displayed message would be Word "abc$cbd" is NOT a word of the L language If the entered word is abc$cba instead, the displayed message would be: Word "abc$cba" IS a word of the L language Example method specification: public static boolean isInLanguage (string str) Make your methods fail-safe, i.e handle exceptions (try/catch) or use if/else statements for error testing/avoidance wherever appropriate
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
