Write a method reversechar to print a sentence in reverse


Problem :

Get familiar with the Stack class in Java and its methods.

Create a new Java Application that has the following methods. Test all your methods in the main method.

1. Write a method reverseChar() to print a sentence in reverse order. Use a Stack to reverse each character.

Example: if the user enters a sentence "ABC DEFG", the program will display "GFED CBA"

2. Write a method reverseWord() to print a sentence reverse order. Use a Stack to reverse each word. Example: If

the user enters a sentence "Live and Let Live" the program will display "Live Let and Live"

3. Write a method secretMessage() that take a sentence containing alphabets and asterisk characters only. All characters are separated by a space. Every character is pushed into a stack. The stack is then processed in the following way:

• All elements are popped

• While popping, if an asterisk is read then the next alphabet in the stack is popped and printed to console

• CRY*S*MTAA*TE* ----> E A S Y

4. Write a method isBalanced() that takes an expression and returns if it has a balanced number of parenthesis or not.

Example: if the user inputs ( 2 + 3 / (4 -2) ) + (5 % 3) the output is true.

If the user inputs ( 2 + 3 / (4 -2) + (5 % 3) the output is false.

5. Write a java method postFixEpr() to evaluate a post fix expression. To make the problem easy assume that we are dealing only with expression that contains only number of 1 digits.

Example of post fix expression

• 3 4 + =

• 7 5 + 8 2 - * =

• 1 3 4 5 6 7 + - * 3 / + =

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a method reversechar to print a sentence in reverse
Reference No:- TGS02895363

Expected delivery within 24 Hours