fork download
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4.  
  5. class Ideone {
  6. public static void main (String[] args) {
  7. char mat[][] = new char[5][5];
  8. List<Integer> random = randomNumbers(65, 90, 25);
  9. int posicao = 0;
  10. for (int ctlin = 0; ctlin < 5; ctlin++)
  11. for (int ctcol = 0; ctcol < 5; ctcol++) mat[ctlin][ctcol] = (char)(int)random.get(posicao++);
  12. for (int ctlin = 0; ctlin < 5; ctlin++) {
  13. for (int ctcol = 0; ctcol < 5; ctcol++) System.out.print(mat[ctlin][ctcol] + " ");
  14. System.out.println();
  15. }
  16. }
  17. public static List<Integer> randomNumbers(int start, int end, int count) {
  18. List<Integer> lista = new ArrayList<>(end - start + 1);
  19. for (int i = start; i <= end; i++) lista.add(i);
  20. Collections.shuffle(lista);
  21. lista = lista.subList(0, count);
  22. return lista;
  23. }
  24. }
  25.  
  26. //https://pt.stackoverflow.com/q/131079/101
Success #stdin #stdout 0.08s 33868KB
stdin
Standard input is empty
stdout
J I E W P 
X U V Y O 
K F H M A 
Q T B N C 
L G S R Z