Results 1 to 4 of 4

Thread: JAVA- divide an array of integers into 2 parts

  1. #1
    Join Date
    Feb 2009
    Posts
    117

    JAVA- divide an array of integers into 2 parts

    I have an array of integers done it this way:

    [1,0,2,0,3,0,4,0,5,1,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,1,15,0,16,0,17,1,18,0,19,0,20,0,21,0,22,0 ,23,0,24,0,25,0]

    I would divide it into two arrays, on the one hand, less than 15 and the other the more than 15:
    then one that goes from 1 to 17:

    [1,0,2,0,3,0,4,0,5,1,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,1,15,0,16,0,17]

    and another 17 to 25:
    [17,1,18,0,19,0,20,0,21,0,22,0,23,0,24,0,25,0]

    you have any idea about it?
    thanks

  2. #2
    Join Date
    Mar 2008
    Posts
    227

    Re: JAVA- divide an array of integers into 2 parts

    As ever in the second array which should not be in very large number, all the numbers are interspersed with zero and one?
    What you can not do?

  3. #3
    Join Date
    Feb 2009
    Posts
    117

    Re: JAVA- divide an array of integers into 2 parts

    represent the previous state .. is a bit difficult to explain
    represent the previous state .. is a bit difficult to explain

  4. #4
    Join Date
    Mar 2008
    Posts
    227

    Re: JAVA- divide an array of integers into 2 parts

    Then the values are to be considered in pairs.
    This is one possible solution:
    • Create 2 arrays arr1 and arr2 of the same dimension of the original and keep two indices last1 and last2 indicating the position of the element respectively arr1 and arr2.
    • Make a loop over all elements of the input and depending on the value enter in arr1 or arr2 appropriately increasing indices.
    • After completing the cycle with last1 and revenues last2 the actual size of the array and shifts new dimension and you just recopy the array.

Similar Threads

  1. Array of objects in java
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 02:05 AM
  2. Help with two dimensional array java
    By GlassFish in forum Software Development
    Replies: 3
    Last Post: 30-11-2009, 01:57 PM
  3. Array problems in java
    By NetworkeR in forum Software Development
    Replies: 2
    Last Post: 06-11-2009, 02:36 PM
  4. Reading integers from a file into a character array
    By afidelino in forum Software Development
    Replies: 3
    Last Post: 08-08-2009, 11:32 AM
  5. JAVA array
    By Daren in forum Software Development
    Replies: 2
    Last Post: 06-03-2009, 06:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,614,269.08764 seconds with 16 queries