fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<String> calculate = new ArrayList<>();
  13. calculate.add("2.0");
  14. calculate.add("+");
  15. calculate.add("2.0");
  16. calculate.add("-");
  17. calculate.add("1.0");
  18.  
  19. Double cV = Double.parseDouble(calculate.get(0));
  20.  
  21. for(int i = 1; i < calculate.size(); i += 2)
  22. {
  23.  
  24. switch(calculate.get(i))
  25. {
  26. case "+":
  27. cV += Double.parseDouble(calculate.get(i + 1));
  28. break;
  29. case "-":
  30. cV -= Double.parseDouble(calculate.get(i + 1));
  31. break;
  32. }
  33. }
  34.  
  35. System.out.println("= " + cV);
  36. }
  37. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
= 3.0