i copied from worksheet::: Strings of the form A\"B\". The Symbol A\"B\" is a st
ID: 3616850 • Letter: I
Question
i copied from worksheet:::Strings of the form A"B".
The Symbol A"B" is a standard notation for the string that consistsof n consecutive A's followed by n consecutives B's.
Write two methods: iterative and recursive, to recongize this kindof strings.
The pseudocode for a recognition method for this languagefollows:
isAnBn(w)
//return true if w is of the form A"B";
// otherwise return false.
if(the length of w is zero)
return true
else if (w begins with the character A and ends with the characterB)
return isAnBn(w minus its first and last characters)
else
return false
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
note: I think professor wanted do two methods and use messageaccept or reject for system.out.print "accept" and system.out.print"reject" as well.
Can anyone help?
here code, i beleive i did big flaw oh well.
import java.util.Scanner;
public class LabE_1
{
private int isAnBn;
private int BB;
public LabE_1(int isAnBn, int BB)
{
this.isAnBn = isAnBn;
this.BB = BB;
}
public static void main(String [] args)
{
Scanner input = newScanner(System.in);
System.out.print("Enter the A/Bcharacter: ");
int w = input.nextInt();
LabE_1 Character = newLabE_1(isAnBn, w);
Character.w();
}
public static boolean isAnBn
{
if( w > 0)
returntrue;
else if(w.isAnBn &&w.BB)
returnisAnBn(w-isAnBn && BB);
else
returnfalse;
}
public static boolean BB
{
if( w > 0)
returntrue;
else if(w.isAnBn &&w.BB)
returnisAnBn(w-isAnBn && BB);
else
returnfalse;
}
}