some changes in the code and bring the same output as in the image attached public class algorithm { public static void main(String[] args){ String w = " abab"; String table[][] = new String[w.length()][w.length()]; if (w.isEmpty()){ System.out.println("@\n"); } for(int i=1; i
do some changes in the code and bring the same output as in the image attached
public class
public static void main(String[] args){
String w = " abab";
String table[][] = new String[w.length()][w.length()];
if (w.isEmpty()){
System.out.println("@\n");
}
for(int i=1; i<w.length();i++){
if(w.charAt(i)=='a')
table[i][i]="R";
else if(w.charAt(i)=='b')
table[i][i]="T";
}
for(int l=2; l<=w.length();l++){
for(int i=1; i<w.length()-l+1;i++){
int j = i+l-1;
for(int k=i; k<=j-1;k++){
if(table[i][k].contains("T") && table[k+1][j].contains("R"))
table[i][j]="T,R"; //Not sure how to do this part?
else if(table[i][k].contains("R") && table[k+1][j].contains("T"))
table[i][j]="S";
}
}
}
System.out.println("Finished");
System.out.println(w);
for(int i=1;i<w.length();i++){
for(int j=1;j<w.length();j++){
System.out.print(table[i][j]+"\t");}
System.out.println("");
}
//System.out.println((table[1][w.length()-1]));
//if (table[1][w.length()-1].equals("S"))
// System.out.println("Accept");
}
}
![Sample Input
3
2 S AB BB
ЗА ВВ а b
2 вьс
bcb
2 S AA @
ЗА АА х у
3
asd
YYYY
Sample Output
Grammar #1:
bcb: YES
c: NO
Grammar #2:
@: YES
asd: NO
УУуу: ҮES](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe223798c-daac-4756-8890-e1f9b26ea7f3%2F28096e93-9f78-4905-aecd-0a16c33df84e%2Fgj8f22c_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)