ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1226. esreveR redrO

why my code is not working? (JAVA)
Posted by yarmet 7 Apr 2014 02:05

import java.io.IOException;
import java.util.Stack;

public class JavaApplication4 {

    static String reverseMethod(String str) {
       Stack<Character> stack = new Stack();
       StringBuilder out = new StringBuilder();
        for( Character t: str.toCharArray() ) {
            if(t >= 'A' && t <= 'Z' || t >= 'a' && t <= 'z' )  {
                stack.push(t);
            } else {
                while( !stack.isEmpty() ) {
                    out.append(stack.pop());
                }
                out.append(t);
            }
     }
        return out.toString();
    }

    public static void main(String[] args) throws IOException   {
      int simbol;
      StringBuilder str = new StringBuilder();

      while ((simbol = System.in.read()) != -1) {
          str.append(  (char)simbol  );
      }

     System.out.println( reverseMethod(str.toString() ));
    }
}