1

I would like to store the array which I sorted in the last line of code into a new array so that I will be able to use it later on.

I started with generating a an array with 10 random numbers, ranging from 1 to 100 and I used the Arrays class in Java to sort that array in ascending order. I want to store a new array with the numbers that are in ascending order. Is there a way to do this?

public static void main(String args[])
{
    /*
     * Generate a random array of 10 numbers using numbers 1-100
     */

    int[] array = new int[10];       

    System.out.println("Random array:");
    for (int i = 0; i < 10; i++)
    {
        int n = (int)(Math.random()*100 + 1);
        array[i] = n;
        //System.out.println(array[i]);
    }

    System.out.println(Arrays.toString(array));

    System.out.println("\nAscending Order:");

    Arrays.sort(array);      

}
  • Welcome to Stack Overflow! We are a question-and-answer site, not a coders-for-hire service. Please explain what you have tried so far and why it hasn't worked. See: [Why is "Can someone help me?" not an actual question?](http://meta.stackoverflow.com/q/284236) – Joe C Feb 26 '17 at 20:00
  • What do you mean by store it? Do you mean just keep it in a variable – Richard Tingle Feb 26 '17 at 20:01
  • array is already sorted, so just use it. What is the purpose of creating a new array? – OldProgrammer Feb 26 '17 at 20:02

0 Answers0