Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Week 7 Exercise 4 I am currently using Ec;ipse to write in Java Both code and sc

ID: 673858 • Letter: W

Question

Week 7 Exercise 4

I am currently using Ec;ipse to write in Java

Both code and screen shot of the output are required to verify that the program is working correctly. Thanks in advance for both your time and effort.

Here is the stack data structure in JCF:

/******************************
* Week 7 lab - exercise 1: *
* using the java.util Stack *
*******************************/

import java.util.*;

/**

* Class to test the java.util.Stack class.
*/
public class Main
{

public static void main(String[] args)
{
Stack<Character> s = new Stack<Character>();

System.out.println("Insertion of 10 characters in s");
for (int i = 0; i < 10; i++)
{
int x = 32 + (int) (Math.random() * 95);
System.out.println(x + " --> " + (char) x);
s.push((char) x);
}

System.out.println(" Displaying and deleting elements");
for (int i = 0; i < 10; i++)
{
System.out.println("Item at the top: " + s.peek());

s.pop();
}
}
}

Exercise 4: Developing an Application with JCF Write a Java program that uses a stackto test whether an input string is a palindrome. To implement the solution to this problem, use the stack data structure in JCF.

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Palindrome
{
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       String text = "abba";
Stack<Character> stackCharacter = new Stack<Character>();
  
for (int i = 0; i < text.length(); i++) {
stackCharacter.push(text.charAt(i));
}

String reversetText = "";

while (!stackCharacter.isEmpty()) {
reversetText += stackCharacter.pop();
}

if (text.equals(reversetText))
System.out.println("Yes! that is a palindrome.");
else
System.out.println("No! that isn't a palindrome.");

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote