fork(1) 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++)
  12. mat[ctlin][ctcol] = (char)(int)random.get(posicao++);
  13. for (int ctlin = 0; ctlin < 5; ctlin++) {
  14. for (int ctcol = 0; ctcol < 5; ctcol++)
  15. System.out.print(mat[ctlin][ctcol] + " ");
  16. System.out.println();
  17. }
  18. }
  19. public static List<Integer> randomNumbers(int start, int end, int count) {
  20. List<Integer> lista = new ArrayList<>(end - start + 1);
  21. for (int i = start; i <= end; i++) {
  22. lista.add(i);
  23. }
  24. Collections.shuffle(lista);
  25. lista = lista.subList(0, count);
  26. return lista;
  27. }
  28. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
B C E F I 
S O T X H 
R K P W Z 
D G M L Q 
V Y N U J