fork download
  1. import java.io.InputStreamReader;
  2. import java.util.ArrayList;
  3. import java.util.Iterator;
  4. import java.util.List;
  5.  
  6. public class DentakuExec {
  7. public static final String OP_ADD = "+";
  8. public static final String OP_SUB = "-";
  9. public static final String OP_MUL = "*";
  10. public static final String OP_DIV = "/";
  11. public static final String OP_MOD = "%";
  12.  
  13. public static void main(String[] args) {
  14. try {
  15. List<String> params = parse(new InputStreamReader(System.in));
  16.  
  17. Double n1 = new Double(params.get(0));
  18. params.remove(0);
  19.  
  20. for (Iterator<String> it = params.iterator(); it.hasNext();) {
  21. String param1 = it.next();
  22.  
  23. if (param1.equals(OP_ADD)) {
  24. n1 = Dentaku.Add(n1, new Double(it.next()));
  25. } else if (param1.equals(OP_SUB)) {
  26. n1 = Dentaku.Sub(n1, new Double(it.next()));
  27. } else if (param1.equals(OP_MUL)) {
  28. n1 = Dentaku.Mul(n1, new Double(it.next()));
  29. } else if (param1.equals(OP_DIV)) {
  30. n1 = Dentaku.Div(n1, new Double(it.next()));
  31. } else if (param1.equals(OP_MOD)) {
  32. n1 = Dentaku.Mod(n1, new Double(it.next()));
  33. } else {
  34. throw new Exception("OP_ERROR");
  35. }
  36. }
  37.  
  38. System.out.println("result=" + n1);
  39. } catch (Throwable e) {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. private static List<String> parse(InputStreamReader reader) throws Exception {
  45. List<String> params = new ArrayList<String>();
  46.  
  47. int i = -1;
  48.  
  49. loop: while ((i = reader.read()) != -1) {
  50. switch (i) {
  51. case '\r':
  52. case '\n':
  53. break loop;
  54. case ' ':
  55. case ' ':
  56. case ',':
  57. case ',':
  58. break;
  59. case '0':
  60. case '1':
  61. case '2':
  62. case '3':
  63. case '4':
  64. case '5':
  65. case '6':
  66. case '7':
  67. case '8':
  68. case '9':
  69. sb.append(i - '0');
  70. break;
  71. case '0':
  72. case '1':
  73. case '2':
  74. case '3':
  75. case '4':
  76. case '5':
  77. case '6':
  78. case '7':
  79. case '8':
  80. case '9':
  81. sb.append(i - '0');
  82. break;
  83. case '.':
  84. case '.':
  85. sb.append(".");
  86. break;
  87. case '+':
  88. case '+':
  89. if (sb.length() == 0) {
  90. sb.append('0');
  91. }
  92. params.add(sb.toString());
  93. sb = new StringBuffer();
  94. params.add(OP_ADD);
  95. break;
  96. case '-':
  97. case '-':
  98. if (sb.length() == 0) {
  99. sb.append('0');
  100. }
  101. params.add(sb.toString());
  102. sb = new StringBuffer();
  103. params.add(OP_SUB);
  104. break;
  105. case '*':
  106. case '*':
  107. case '×':
  108. params.add(sb.toString());
  109. sb = new StringBuffer();
  110. params.add(OP_MUL);
  111. break;
  112. case '/':
  113. case '/':
  114. case '÷':
  115. params.add(sb.toString());
  116. sb = new StringBuffer();
  117. params.add(OP_DIV);
  118. break;
  119. case '%':
  120. case '%':
  121. params.add(sb.toString());
  122. sb = new StringBuffer();
  123. params.add(OP_MOD);
  124. break;
  125. default:
  126. throw new Exception("PARSE_ERROR code=" + i);
  127. }
  128. }
  129.  
  130. if (sb.length() != 0) {
  131. params.add(sb.toString());
  132. }
  133.  
  134. return params;
  135. }
  136. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:6: error: class DentakuExec is public, should be declared in a file named DentakuExec.java
public class DentakuExec {
       ^
Main.java:24: error: cannot find symbol
					n1 = Dentaku.Add(n1, new Double(it.next()));
					     ^
  symbol:   variable Dentaku
  location: class DentakuExec
Main.java:26: error: cannot find symbol
					n1 = Dentaku.Sub(n1, new Double(it.next()));
					     ^
  symbol:   variable Dentaku
  location: class DentakuExec
Main.java:28: error: cannot find symbol
					n1 = Dentaku.Mul(n1, new Double(it.next()));
					     ^
  symbol:   variable Dentaku
  location: class DentakuExec
Main.java:30: error: cannot find symbol
					n1 = Dentaku.Div(n1, new Double(it.next()));
					     ^
  symbol:   variable Dentaku
  location: class DentakuExec
Main.java:32: error: cannot find symbol
					n1 = Dentaku.Mod(n1, new Double(it.next()));
					     ^
  symbol:   variable Dentaku
  location: class DentakuExec
6 errors
stdout
Standard output is empty