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. Random random = new Random();
  13. String elemento[] = {"Ar", "Terra","Agua","Fogo","Madeira"};
  14. int x = 5;
  15. int c = 0;
  16. int p = -1;
  17. String escolhas[] = new String[x];
  18. while (c < x)
  19. {
  20. p = random.nextInt(((x-c)));
  21. escolhas[c] = elemento[p];
  22. if (p != ((x-c)-1))
  23. {
  24. elemento[p] = elemento[(x-c)-1];
  25. elemento[(x-c)-1] = null;
  26. }
  27. else
  28. {
  29. elemento[(x-c)-1] = null;
  30. }
  31.  
  32. c++;
  33. }
  34. for(String d: escolhas)
  35. {
  36. System.out.println(d);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Agua
Ar
Fogo
Terra
Madeira