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.
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?
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...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
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...
Write a Java part code to do the following   : ** Suppose a file called infile stored...
Write a Java part code to do the following   : ** Suppose a file called infile stored in drive D: ,filled with five integers(1000,200,3030,40 and 500) Read  the integers from infile then store them in array called ar[] and print it elements. Method called search( ) to print the location of   value 500. Method called sort() to sort array elements. Build another file called outfile in drive D: to save the sorted array elements . Note : Use ArrayIndexOutOfBoundsException when you use array...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
Java Programming I need to create an application that have an Arraylist string with 6 elements....
Java Programming I need to create an application that have an Arraylist string with 6 elements. Then it ask the user to input more elements until it reaches 10 elements in total. After that the application remove 1 element with remove() by index. To finalize it uses a for-each loop to display the list. Thanks for your help!
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...