Results 1 to 3 of 3

Thread: Computer Science java help!

  1. #1 Computer Science java help! 
    New Member
    Join Date
    Jun 2011
    By using Java in Netbeans or JCreator i need to find out how to

    Write a program that creates 2 arrays, A and B, of 30 items each. Fill A with 30 random numbers either by input or using a random number generator. Use an insertion sort to transfer the numbers from A into B in descending order.

    Please help we are using the current book of

    Reply With Quote  


  3. #2  
    Forum Freshman
    Join Date
    May 2011
    London, Earth.
    Declare your two arrays and set the capacity for each to 30
    Declare a new random eg Random randomNumber = new Random();
    Declare an int for a counter eg int counterIndex =0;

    loop through each index in array A
    insert a random number into each index using the randomNumber.nextInt();
    end loop

    Sort array A using Arrays.sort();

    Loop through array A from the last index
    insert each into B starting at the first index eg B[counterIndex];
    increment counterIndex
    end loop

    There are other ways but if you can't do this yourself then this is probably the easiest solution for you.

    Good luck.

    Reply With Quote  

  4. #3  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    You'll almost certainly get points off for using Arrays.sort() for this problem.

    That said, the homework policy around here is that we can give hints, but we won't do it for you. If you can ask more specific questions, it'd be easier to help.
    Reply With Quote  

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts