Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int my_random_arr[] = new int[4];
- int cur = 0;
- Random r = new Random();
- while(cur < 4){
- // get random number
- int new_number = r.nextInt(9);
- // check the new number is in my_random_arr
- int idx = 0;
- while(idx < cur){
- // try to find same number in here
- if (new_number == my_random_arr[idx]) {
- break;
- }
- idx++;
- }
- if ( idx == cur ) {
- my_random_arr[idx] = new_number;
- cur++;
- }
- }
- for (int num : my_random_arr) {
- System.out.print(num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement