A word-unit palindrome is a string of words such that the wordsread the sameforward and backward. For example, the quote“Fallleaves after leaves fall” is a word-unit palindrome. Considerupper- and lowercase versions of a letter to be the same letter.Write a program (using stacks and/or queues) to test an inputstring and tell whether or not it is a word-unit palindrome. INJAVA!!!
Solution
java code:
package palindromestack;
import java.util.Scanner;
import java.util.Stack;
public class PalindromeStack {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
String original;
int n =0;
boolean flag = true;
//get input string
System.out.print(“Enter the string:”);
original= sc.nextLine();
//split into words
String token[] =original.split(” “);
String[] reverse =new String[token.length];
//create stack object
Stack st =