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.  
  16. boolean exist;
  17. for(int j = 0; j<4; j++){
  18. exist = false;
  19.  
  20. int r, temp;
  21. r = rnd.get( 5 );
  22. System.out.println("r = "+r);
  23.  
  24. //losowanie indeksu do tablicy collection[]
  25. temp = collection[r];
  26.  
  27.  
  28.  
  29. for(int i = 0; i<6; i++)
  30. {
  31. //sprawdzanie czy tej wartosci juz nie ma w tablicy result
  32. if(temp == result[i]){
  33. exist = true;
  34. break;
  35. }
  36. }
  37. if(exist == false){
  38. result[j] = temp;
  39. }
  40. else
  41. {
  42. j--;
  43. }
  44.  
  45. }
  46. }
  47. }
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