-1

Im working on a task where i need to randomize a user specified amount of numbers between 0 and 999 with the help of an array. Then i need to create two new Arrays sorting the numbers from the previous array one with the numbers ranging from 0 to 499 and one with the numbers between 500 and 999. Its important that the arrays have an exact size of the amount of numbers that needs to go in them, thats why im using a arraylist. Would appreciate some tips on how to do this!

here is my code so far:

public static void main(String[] args)                                                      
{




    Scanner in = new Scanner(System.in);                                                    
    System.out.print("How many random numbers? 0 – 999 do you want? ");     
    int varde = in.nextInt();   
    System.out.print("");
    System.out.println("Here are your numbers:");


    int randomArray[]=new int[varde];                                                       
    for(int i = 0; i<varde; i++)

    {   
        randomArray [i] = (int) (Math.random () * 999); 
        System.out.print(" "+randomArray[i]);


    ArrayList lowNumbers = new ArrayList();
    if (randomArray.equals(""))
    {
        lowNumbers.add(randomArray);
        System.out.println("Low Numbers: "+lowNumbers);
    }

    }
manlio
  • 18,345
  • 14
  • 76
  • 126
  • 1
    You should describe what problem you're having with your current code. – kviiri May 23 '14 at 13:04
  • This looks like Java; you should tag (or at least mention) what language this is. – Scott Hunter May 23 '14 at 13:05
  • Furthermore this really looks like a homework assignment and looking at the code I'd advice you reread the slides/notes provided by your class and figure out what you should do. – Joel Witteveen May 23 '14 at 13:07
  • The problem im mainly having is that i dont know how i would select the numbers ranging from 499 to 999 (and vice versa) and then place them in a new array. Yes ofcourse im not asking for you to create it for me, i need pointers and tips on how to do it! – user3529167 May 23 '14 at 13:07
  • You already asked a really similar question here: http://stackoverflow.com/questions/23044000/print-all-numbers-in-between-a-set-value-in-an-array I'd vote on closing this question. – Joel Witteveen May 23 '14 at 13:10
  • randomArray is an array of ints; what would ever expect it to equals("")? – Scott Hunter May 23 '14 at 13:10

1 Answers1

0

You could count the low & high numbers as you fill randomArray, so you know how big to make your 2 arrays, then loop over randomArray and test each value to decide which array to put it in.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101