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