Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. for(int i=0; i<niza.length; i++) {
  2.             if(niza[i] == "+") {
  3.                 int a = stack.pop();
  4.                 int b = stack.pop();
  5.                 int res = a + b;
  6.                 stack.push(res);
  7.             }
  8.             else if(niza[i] == "-") {
  9.                 int a = stack.pop();
  10.                 int b = stack.pop();
  11.                 int res = a - b;
  12.                 stack.push(res);
  13.             }
  14.             else if (niza[i] == "*") {
  15.                 int a = stack.pop();
  16.                 int b = stack.pop();
  17.                 int res = a * b;
  18.                 stack.push(res);
  19.             }
  20.             else if(niza[i] == "/") {
  21.                 int a = stack.pop();
  22.                 int b = stack.pop();
  23.                 int res = a / b;
  24.                 stack.push(res);
  25.             }
  26.             else {
  27.                 int p = Integer.parseInt(niza[i]);
  28.                 stack.push(p);
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement