Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(int i=0; i<niza.length; i++) {
- if(niza[i] == "+") {
- int a = stack.pop();
- int b = stack.pop();
- int res = a + b;
- stack.push(res);
- }
- else if(niza[i] == "-") {
- int a = stack.pop();
- int b = stack.pop();
- int res = a - b;
- stack.push(res);
- }
- else if (niza[i] == "*") {
- int a = stack.pop();
- int b = stack.pop();
- int res = a * b;
- stack.push(res);
- }
- else if(niza[i] == "/") {
- int a = stack.pop();
- int b = stack.pop();
- int res = a / b;
- stack.push(res);
- }
- else {
- int p = Integer.parseInt(niza[i]);
- stack.push(p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement