Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.io.*;
  6. import java.lang.Throwable.*;
  7.  
  8. public class Final{
  9. public static void main(String[]args){
  10.  
  11. Scanner in = new Scanner (System.in);
  12. System.out.print("Enter: ");
  13. String s = in.nextLine();
  14.  
  15.  
  16. int pipe[] = new int [s.length()];
  17. int index = 0;
  18.  
  19. for(int i =0; i < s.length(); i++)
  20. {
  21.  
  22.  
  23. // strip out white spaces
  24. if (Character.isDigit(s.charAt(i))) {
  25. int n = 0;
  26.  
  27. do {
  28. n = n * 10 + s.charAt(i) - (int) '0';
  29. i++;
  30. }
  31. while (Character.isDigit(s.charAt(i)));
  32.  
  33. pipe[index] = n;
  34. System.out.println("index= " + index);
  35. System.out.println(pipe[index]);
  36. index ++;
  37.  
  38.  
  39. }
  40. else if (s.charAt(i) == '+'){
  41.  
  42. System.out.println("index= " + index);
  43. System.out.println("+");
  44. pipe[index-2] = pipe[index-2] + pipe[index-1];
  45. System.out.println("r: " + pipe[index-2]);
  46. index = index - 1;
  47.  
  48. }
  49. else if (s.charAt(i) == '-'){
  50.  
  51. System.out.println("index= " + index);
  52. System.out.println("-");
  53. pipe[index-2] = pipe[index-2] - pipe[index-1];
  54.  
  55. System.out.println("r: " + pipe[index-2]);
  56. index = index - 1;
  57. }
  58. else if (s.charAt(i) == '*'){
  59. System.out.println("index= " + index); System.out.println("*");
  60.  
  61. pipe[index-2] = pipe[index-2] * pipe[index-1];
  62.  
  63. System.out.println("r: " + pipe[index-2]);
  64. index = index - 1;
  65. }
  66. else if (s.charAt(i) == '/'){
  67.  
  68. System.out.println("index= " + index); System.out.println("/");
  69. pipe[index-2] = pipe[index-2] / pipe[index-1];
  70.  
  71. System.out.println("r: " + pipe[index-2]);
  72. index = index - 1;
  73. }
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }
  80. }
Add Comment
Please, Sign In to add comment