fork(1) download
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. public class Main {
  6.  
  7. final int[] stack = new int[10];
  8. private int countStackFill = 0;
  9.  
  10. public static void main(String[] args) {
  11.  
  12. Main main = new Main();
  13. main.readStackData("C:\\Users\\Public\\odczyt.txt");
  14.  
  15. }
  16.  
  17. public void readStackData(String filePath) {
  18. try (BufferedReader in = new BufferedReader(new FileReader(filePath))) {
  19. String sign;
  20. while ((sign = in.readLine()) != null) {
  21. if (sign.equals("+")) {
  22. push(Integer.valueOf(in.readLine()));
  23. }
  24. else if (sign.equals("-")) {
  25. pop();
  26. }
  27. else {
  28. System.out.println("Wrong input");
  29. }
  30. }
  31. }
  32. catch (IOException e) {}
  33. }
  34.  
  35. void pop() {
  36. if (getCountStackFill() != 0) {
  37. System.out.println(this.stack[this.countStackFill - 1]);
  38. this.stack[this.countStackFill - 1] = -1;
  39. this.countStackFill--;
  40. }
  41. else {
  42. System.out.println(":(");
  43. }
  44. }
  45.  
  46. void push (int num) {
  47. if (getCountStackFill() < 10) {
  48. this.stack[this.countStackFill] = num;
  49. this.countStackFill++;
  50. System.out.println(":)");
  51. }
  52. else {
  53. System.out.println(":(");
  54. }
  55. }
  56.  
  57. public int getCountStackFill() {
  58. return countStackFill;
  59. }
  60.  
  61. }
  62.  
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Standard output is empty