fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Random;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. static Random aleatorio = new Random();
  12.  
  13. public static void arrayWord () {
  14.  
  15. String[] wordgame = {
  16. "TEA",
  17. "COFFEE",
  18. "BOAT",
  19. "SUN",
  20. "SEA"
  21.  
  22. };
  23.  
  24. int idx = aleatorio.nextInt(wordgame.length);
  25. String palavraEscolhida = (wordgame[idx]);
  26.  
  27. System.out.println(palavraEscolhida);
  28. System.out.println(scramble(palavraEscolhida));
  29.  
  30. }
  31.  
  32. public static String scramble(String inputString )
  33. {
  34. // Convert your string into a simple char array:
  35. char[] a = inputString.toCharArray();
  36.  
  37. // Scramble the letters using the standard Fisher-Yates shuffle,
  38. for( int i=0 ; i<a.length ; i++ )
  39. {
  40. int j = aleatorio.nextInt(a.length);
  41. // Swap letters
  42. char temp = a[i];
  43. a[i] = a[j];
  44. a[j] = temp;
  45. }
  46.  
  47. return new String(a);
  48. }
  49.  
  50. public static void main (String[] args){
  51. arrayWord();
  52. }
  53. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
TEA
ETA