1.) Take in a word from a user 2.) Create a character stack that will store the
ID: 3531130 • Letter: 1
Question
1.) Take in a word from a user 2.) Create a character stack that will store the word. Use a for loop o push each letter onto the stack. 3.) Write a method that takes in the Stack and String as parameters. It should return a boolean if the word is palindrome. public static boolean isPalindrome(Stackin, String input_str) 5.)Print and tell the user if the word is a palindrome or not. My Code so far is----------------- //Using stacks import java.util.Scanner; public class Bowen9 { public static void main(String [] args) { Scanner input = new Scanner(System.in); System.out.println("Type in a word: "); String word = input.nextLine(); Stack letters = new Stack(); for(int i = 0; iin, String input_str) } }Explanation / Answer
import java.util.Scanner;
public class Bowen9
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Type in a word: ");
String word = input.nextLine();
Stack letters = new Stack();
for(int i=0;i<word.length,i++)
{
letters.push(word.substring(i,i+1));
}
if(isPalindrome(S,word))
{
System.out.println("Given word is palindrome");
}
else
{
System.out.println("Given word is not palindrome");
}
}
public static boolean isPalindrome(Stack S, String input_str)
{
string temp=null;
while(!S.empty())
{
temp=S.pop()+temp;
}
if(temp.equals(input_str))
{
return true;
}
return false;
}
}
Notify me, if you have any problem
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.