(String args[])
| 3 | |
| 4 | public class Question2 { |
| 5 | public static void main(String args[]) { |
| 6 | String str = "HelloWorld"; |
| 7 | |
| 8 | Stack<Character> s = new Stack<>(); |
| 9 | |
| 10 | int i=0; |
| 11 | while(i<str.length()) { |
| 12 | s.push(str.charAt(i)); |
| 13 | i++; |
| 14 | } |
| 15 | |
| 16 | StringBuilder result = new StringBuilder(""); |
| 17 | while(!s.isEmpty()) { |
| 18 | result.append(s.pop()); |
| 19 | } |
| 20 | str = result.toString(); |
| 21 | System.out.println(str); |
| 22 | } |
| 23 | } |