Advertisement
Guest User

ONP2

a guest
Mar 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2.  
  3. public class Onp2 {
  4.  
  5. public static void main(String[] args) {
  6. int j = 0;
  7. String[] stack = new String[10];
  8. int stackPosition = -1;
  9. for(String str: args)
  10. {
  11. stack[j] = "";
  12. if(str.endsWith("=")){
  13. for(int i=0; i< str.length(); i++)
  14. if(str.charAt(i) >= '0' && str.charAt(i) <= '9' || str.charAt(i) == '.'){
  15. stack[++stackPosition] = str.charAt(i) + " ";
  16. //if(!(str.charAt(i+1) >= '0' && str.charAt(i+1) <= '9' && str.charAt(i+1) == '.'))
  17. //stack[stackPosition] += " ";
  18. }
  19. else{
  20. switch(str.charAt(i)){
  21. case '-':
  22. case '+':{
  23. stack[--stackPosition] = "( " + stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1] + ")";
  24. break;
  25. }
  26. case '*':
  27. case '/':
  28. case '^':
  29. stack[--stackPosition] = stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1];
  30. break;
  31. default:
  32. break;
  33.  
  34. }
  35. }
  36. }
  37. else
  38. System.out.println(str + ": Bledne rownanie");
  39. System.out.println(args[j]);
  40. System.out.println(stack[j]);
  41. j++;
  42. }
  43.  
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement