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 enum Operation {
  11. PLUS { double eval(double x, double y) { return x + y; } },
  12. MINUS { double eval(double x, double y) { return x - y; } },
  13. TIMES { double eval(double x, double y) { return x * y; } },
  14. DIVIDE { double eval(double x, double y) { return x / y; }};
  15.  
  16. // Do arithmetic op represented by this constant
  17. abstract double eval(double x, double y);
  18. }
  19.  
  20.  
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23. double x = Double.parseDouble(args[0]);
  24. double y = Double.parseDouble(args[1]);
  25. for (Operation op : Operation.values())
  26. System.out.printf("%f%s%f=%f%n",x,op,y,op.eval(x,y));
  27.  
  28. }
  29. }
Runtime error #stdin #stdout #stderr 0.04s 320576KB
stdin
5
6
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at Ideone.main(Main.java:23)