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. static int[] items = {1,0,0,1,2,2,1};
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. for(int x = 0; x < items.length; x++) {
  15. boolean response = useItem(x);
  16. System.out.println("Used item=" + response);
  17. }
  18. }
  19.  
  20. public static boolean useItem(int place) {
  21. switch(items[place]) {
  22. case 0:
  23. return false;
  24. case 1:
  25. items[place] = 0;
  26. return true;
  27. case 2:
  28. items[place] = 1;
  29. return true;
  30. default:
  31. return false;
  32. }
  33. }
  34. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
Used item=true
Used item=false
Used item=false
Used item=true
Used item=true
Used item=true
Used item=true