class stringPatten{
//You are required to make a simple JAVA program to ask the user for a character string,
//test whether it contains a substring a*b or not, and print it
private int f = 0, l = 0;
String str1 = new String();
public boolean interpret(String str){
str1 = str;
int len = str1.length() - 1;
char[] char1 = str1.toCharArray();
int i = 0, count = 0;
boolean bool = true;
while ((i <= len) & bool)
{
char aa = char1[i++];
if (( aa == 'b') || (aa == 'B')){
l = i;
int j = i - 2;
while ((j >= 0) & (char1[j] == 'a' || char1[j] == 'A')){
j--;
}
f = j + 1;
bool = false;
}
}
return bool;
}
public int getf(){
return f;
}
public int getl(){
return l;
}
}
public class Main{
public static void main(String[] arg) {
String str1 = new String();
stringPatten strP = new stringPatten();
boolean bool = true;
try
{
str1 = arg[0];
} catch (ArrayIndexOutOfBoundsException e)
{
System.out.println(" Sorry for the incorrect input, following the input as ");
System.out.println(" java Main InputString ");
return;
}
//method interpret to judge whether the given string satisfies the patten of a*b or not
bool = strP.interpret(str1);
if (bool == false)
System.out.println(" This string has a patten of a*b " + str1.substring(strP.getf(), strP.getl()) );
else
System.out.println(" This string doesn't satisfy a patten of a*b " );
}
}