-
-
Save hazartilirot/92ebe81d13ba95095b16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class StackTest { | |
public static void main(String[] args) { | |
Stack<Character> stack1 = new Stack<Character>(); | |
System.out.print("input: "); | |
Scanner in = new Scanner(System.in); | |
for(char ch : in.nextLine().toCharArray()) | |
stack1.push(ch); | |
while(!stack1.empty()) { | |
System.out.print(stack1.pop()); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Мое решение задачи:
public class RevertString {
public static String revert(String str) {
StringBuilder builder = new StringBuilder();
for (int index = str.length() - 1; index >= 0; index -= 1) {
builder.append(str.substring(index, index + 1));
}
return builder.toString();
}
}