Create a java program where you apply the concept of PDA (Pushdown automata) using stack where program will check if the input is a PALINDROME or not.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a java program where you apply the concept of PDA (Pushdown automata) using stack where program will check if the input is a PALINDROME or not. 

See attached photo for the example (you can use conditionals to make the program possible)

PUSH DOWN AUTOMATA PROGRAM
IN JAVA FOR EQUAL NO OF A'S AND
B'S
JUNE 5, 2015 ANKUR LEAVE A COMMENT
123456789912341516718 19 281223425 25 7 28 29 38 31 32 33 34 35368388245455558
10
20
26
27
30
37
39
40
41
47
49
import java.io.*;
class Pda {
}
static char st[] = new char[20];
static int ptr = 0;
static void push(char e) {
st[ptr] = e;
ptr++;
}
static void pop() {
ptr--;
}
public static void main(String Args[]) throws IOException
BufferedReader obj = new BufferedReader (new Inputstr
string ip;
System.out.println("Enter String:");
ip = obj.readLine();
int 1;
boolean f= false;
int i;
for (i = 0; i <ip.length(); i++) {
if (ip.charAt(i) == 'a') {
push('a');
For
for
If
} else {
}
50 /* OUTPUT
break;
(iip.length(); i++) {
if (ip.charAt(i) == 'a') {
f = false;
break;
} else {
}
(ptr == 0) {
f = true;
pop();
if (f == true) {
System.out.println("string Accepted");
System.out.println("string rejected");
} else {
Transcribed Image Text:PUSH DOWN AUTOMATA PROGRAM IN JAVA FOR EQUAL NO OF A'S AND B'S JUNE 5, 2015 ANKUR LEAVE A COMMENT 123456789912341516718 19 281223425 25 7 28 29 38 31 32 33 34 35368388245455558 10 20 26 27 30 37 39 40 41 47 49 import java.io.*; class Pda { } static char st[] = new char[20]; static int ptr = 0; static void push(char e) { st[ptr] = e; ptr++; } static void pop() { ptr--; } public static void main(String Args[]) throws IOException BufferedReader obj = new BufferedReader (new Inputstr string ip; System.out.println("Enter String:"); ip = obj.readLine(); int 1; boolean f= false; int i; for (i = 0; i <ip.length(); i++) { if (ip.charAt(i) == 'a') { push('a'); For for If } else { } 50 /* OUTPUT break; (iip.length(); i++) { if (ip.charAt(i) == 'a') { f = false; break; } else { } (ptr == 0) { f = true; pop(); if (f == true) { System.out.println("string Accepted"); System.out.println("string rejected"); } else {
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY