Guest User

Untitled

a guest
Oct 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.util.Random;
  7. /**
  8. *
  9. * @author WIF170039
  10. */
  11. public class L5Q2 {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) {
  17. // TODO code application logic here
  18. int [] num = new int [10];
  19. int number;
  20.  
  21. Random rand = new Random ();
  22.  
  23. System.out.println("The random integers are :");
  24.  
  25. for (int i=0; i<10; i++) { //for (int i=0; i<number.length; i++) number.length is #of array
  26. num [i] = rand.nextInt(21);
  27.  
  28. for (int j=0; j<i; j++) {
  29. if (num[i]==num[j]) {
  30. i--;
  31. break; //teruskan compare
  32.  
  33. /*
  34. if (num[i]!=num[j]) {
  35. continue; *teruskan compare*
  36. }
  37. else {
  38. i--;
  39. break;
  40. }
  41. */
  42. }
  43.  
  44. }
  45. }
  46. for (int i=0; i<10; i++) {
  47. System.out.print(num[i] + " " );
  48. }
  49.  
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment