JAVA Create an array that contains a list of integers in an

!!!!!!!JAVA!!!!

Create an array that contains a list of integers, in an ascending order, from 1 to a large enough number (e.g., 1000000 so that the running time of building a tree containing those numbers will be at least 1 second). (b) Create an array that contains a list of integers that is the same as the 1st but in descending order (e.g., from 1000000 to 1). (c) Create an array that has the same numbers as above, but the order of the numbers (e.g., 1 - 1000000) is random. You can use a random number generator to decide and put a number into the array.

Solution

Hi, I have created three array of size 10000, you can use the same code snippt to create an array of any size with any numbers set.

Please let me know in case of any issue.

import java.util.Random;

public class Test {

   public static void main(String[] args) {

       // 1. creation of an array in assending array

       int arr[] = new int[10000];

       // filling an array with 1 to 10000 numbers

       for(int i=0; i<10000; i++)

           arr[i] = i+1;

      

      

       // 1. creation of an array in descending array

       int arr2[] = new int[10000];

       // filling an array with 10000 to 1 numbers

       for(int i=10000; i>=1; i--)

           arr[i-1] = i;

      

       // creating third array

       Random rand = new Random();

       int arr3[] = new int[10000];

       for(int i=0; i<10000; i++)

           arr[i] = rand.nextInt(10000)+1; // random number in range 1-10000

   }

}

!!!!!!!JAVA!!!! Create an array that contains a list of integers, in an ascending order, from 1 to a large enough number (e.g., 1000000 so that the running time

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site