Question

how do i create an array of 65536 elements with random non repeated numbers and it...

how do i create an array of 65536 elements with random non repeated numbers and it is sorted?

in java please. thank you

Homework Answers

Answer #1

ANSWER :

CODE :

import java.util.Random;
import java. util. Arrays;

public class Main
{
public static void main (String[]args)
{
// creating object to generate random numbers
Random rand = new Random ();
//
Integer arr[] = new Integer[65536];
  
for (int i = 0; i < 65536; i++)
{
//random number in range of 70000
Integer random_num = rand.nextInt (70000);
//if already present, generate new random number and then insert into array
while(Arrays.asList(arr).contains(random_num))
{
   random_num = rand.nextInt (70000);
}
   arr[i] = random_num;
}
//sorting arrays elements
Arrays.sort(arr);
  
for (int i = 0; i < 65536; i++)
{
System.out.println(arr[i]);

}
}
}

OUTPUT :

THANK YOU...!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers (choosing between a range of 20 to 90) and then outputs the largest number.
in python Generates 50,000 random numbers and puts them in an array. Sorts the numbers using...
in python Generates 50,000 random numbers and puts them in an array. Sorts the numbers using any sorting technique (Selection sort is fine, but you can try another one). This should take a few minutes to run. Ask the user for a number between 0 and 20,000,000 and search for it in your sorted array using a simple linear search. Is this a good idea? Ask the user for a number between 0 and 20,000,000 and search for it in...
Assume that we have a sorted array a[n]with n non-negative numbers. a. Develop an algorithm using...
Assume that we have a sorted array a[n]with n non-negative numbers. a. Develop an algorithm using divide-and-conquer to search for an element x in this sorted array a[n]. This algorithm will take an input of a sorted array a[n], and return the index of element x is an element of a[n], or return -1if xis NOT an element of this array. b. Analyze the time complexity of this algorithm.
Write a program to determine the minimum element in an array of ten elements. The program...
Write a program to determine the minimum element in an array of ten elements. The program should have the following: 1. Class Name as ArrayProcessing. The main method should create an array of size 10 2. There should be two methods besides the main method in the class namely inputArray and MinimumElement 3. InputArray method should assign the ten elements in the array. Use scanner to input these elements. The array of 10 numbers in the method "InputArray" should be...
How do I generate random numbers? What's the best way to generate random numbers?
How do I generate random numbers? What's the best way to generate random numbers?
Write a program in Java that creates an array of doubles. The array must have size...
Write a program in Java that creates an array of doubles. The array must have size 1000. Fill this array with random numbers between 0 and 1. Then compute and print the total value of all the elements of the array, the mean, the minimum, and the maximum. Filling the array with random numbers must be done by a method that you define and implement. Computing and printing the statistics must be done by another method, which again you must...
Let A[1, . . . , n] be an array of n distinct numbers. If i...
Let A[1, . . . , n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. 1. Which arrays with distinct elements from the set {1, 2, . . . , n} have the smallest and the largest number of inversions and why? State the expressions exactly in terms of n. 2. For any 0 < a < 1/2, construct an array for...
for C++, I am trying to create a function that prints a 2D array. Can you...
for C++, I am trying to create a function that prints a 2D array. Can you instruct me on the easiest way to do so? Please do not make it complicated, we have no started learning about pointers yet, either, so it can't be done that way.
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...