Advertisement
Guest User

ONP2e

a guest
Mar 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 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. }
  17. else{
  18. switch(str.charAt(i)){
  19. case '-':
  20. case '+':{
  21. stack[--stackPosition] = "( " + stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1] + ") ";
  22. break;
  23. }
  24. case '*':
  25. case '/':
  26. case '^':
  27. stack[--stackPosition] = stack[stackPosition] + str.charAt(i) + " " + stack[stackPosition+1];
  28. break;
  29. case '=':
  30. stack[stackPosition] += str.charAt(i) + " ";
  31. break;
  32. default:
  33. break;
  34.  
  35. }
  36. }
  37. }
  38. else
  39. System.out.println(str + ": Bledne rownanie");
  40. System.out.println(args[j]);
  41. System.out.println(stack[j]);
  42. j++;
  43. }
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement