fork download
  1. class Try{
  2.  
  3. public static void main(String args[]){
  4. int[] collection = new int[6];
  5.  
  6. collection[0] = 8;
  7. collection[1] = 2;
  8. collection[2] = 4;
  9. collection[3] = 2;
  10. collection[4] = 21;
  11. collection[5] = 3;
  12.  
  13. Random rnd = new Random();
  14. int[] result = new int[4];
  15. boolean exist = false;
  16.  
  17. int r, temp;
  18. r = rnd.get( 5 );
  19. System.out.println("r = "+r);
  20.  
  21. //losowanie indeksu do tablicy collection[]
  22. temp = collection[r];
  23.  
  24. for(int i = 0; i<6; i++)
  25. {
  26. //sprawdzanie czy tej wartosci juz nie ma w tablicy result
  27. if(temp == result[i]){
  28. exist = true;
  29. r = rnd.get( 5 );
  30. break;
  31. }
  32. if(exist == false){
  33. result[i] = temp;
  34. r = rnd.get( 5 );
  35. }
  36. }
  37.  
  38. }
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: cannot find symbol
		Random rnd = new Random();
		^
  symbol:   class Random
  location: class Try
Main.java:13: error: cannot find symbol
		Random rnd = new Random();
		                 ^
  symbol:   class Random
  location: class Try
2 errors
stdout
Standard output is empty