Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 13 Weeks Ago, 1 Day Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Which Expression:
Write a method that takes a String as a parameter and prints to the screen which of the regular expressions shown below is satisfied by the String. The String can only contain the characters a and b and you must use the.matches(<...>) method with a regular expression. The method doesn't have to return anything.
Â
Regular Expression No.                 Regular Expression
1:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â a(b|a)b
2:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ab)* b
3:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â a(b|a)*
4:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ( (a|b) a)*
If the String satisfies more than one regular expression print each one on a new line. See output below. If the String does not satisfy any expression have a valid print statement stating this fact. In your main method call the method with user input.
Â
Test case(s)
-----
Sample Input:
abb
Sample Output:
1
2
3
-----
Sample Input:
ababad
Sample Output:
Not in the language
-----