Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import java.lang.Throwable.*;
- public class Final{
- public static void main(String[]args){
- Scanner in = new Scanner (System.in);
- System.out.print("Enter: ");
- String s = in.nextLine();
- int pipe[] = new int [s.length()];
- int index = 0;
- for(int i =0; i < s.length(); i++)
- {
- // strip out white spaces
- if (Character.isDigit(s.charAt(i))) {
- int n = 0;
- do {
- n = n * 10 + s.charAt(i) - (int) '0';
- i++;
- }
- while (Character.isDigit(s.charAt(i)));
- pipe[index] = n;
- System.out.println("index= " + index);
- System.out.println(pipe[index]);
- index ++;
- }
- else if (s.charAt(i) == '+'){
- System.out.println("index= " + index);
- System.out.println("+");
- pipe[index-2] = pipe[index-2] + pipe[index-1];
- System.out.println("r: " + pipe[index-2]);
- index = index - 1;
- }
- else if (s.charAt(i) == '-'){
- System.out.println("index= " + index);
- System.out.println("-");
- pipe[index-2] = pipe[index-2] - pipe[index-1];
- System.out.println("r: " + pipe[index-2]);
- index = index - 1;
- }
- else if (s.charAt(i) == '*'){
- System.out.println("index= " + index); System.out.println("*");
- pipe[index-2] = pipe[index-2] * pipe[index-1];
- System.out.println("r: " + pipe[index-2]);
- index = index - 1;
- }
- else if (s.charAt(i) == '/'){
- System.out.println("index= " + index); System.out.println("/");
- pipe[index-2] = pipe[index-2] / pipe[index-1];
- System.out.println("r: " + pipe[index-2]);
- index = index - 1;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment