fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] expr = new String[]{"67", "+", "45", "-", "12", "*", "5", "/", "78"};
  13. int current = 0;
  14. StringBuilder postfix = new StringBuilder();
  15.  
  16. // handle first three
  17. postfix.append(expr[current]).append(" ");
  18. postfix.append(expr[current+2]).append(" ");
  19. postfix.append(expr[current+1]).append(" ");
  20. current += 3;
  21.  
  22. // handle rest
  23. while( current <= expr.length-2 ){
  24. postfix.append(expr[current+1]).append(" ");
  25. postfix.append(expr[current]).append(" ");
  26. current += 2;
  27. }
  28.  
  29. System.out.println(postfix.toString());
  30. }
  31. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
67 45 + 12 - 5 * 78 /