Skip to content

Instantly share code, notes, and snippets.

@hazartilirot
Created January 31, 2012 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazartilirot/92ebe81d13ba95095b16 to your computer and use it in GitHub Desktop.
Save hazartilirot/92ebe81d13ba95095b16 to your computer and use it in GitHub Desktop.
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();
}
}
@javadev
Copy link

javadev commented Feb 1, 2012

Мое решение задачи:

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();
}

public static void main(String[] args) {
    System.out.println(revert("Hello, Java"));
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment