Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Splitting an Array?

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Splitting an Array?

    I have an assignment in class due that has four optional assignments. I have already completed one option, but I wanted to complete one of the other ones that I think I am capable of doing. Basically, the assignment says:

    Write a class with a public method that takes a single argument which is an array of integers, and prints to the console those integers in a two-column format, with the first half of the numbers appearing in the first column and second half in the second column. The input array may contain any number of integers.

    Now I have a basic idea of how to start this:

    public void printIntegers (int[] myArray){ // do I have to declare myArray beforehand in the class?

    but I can't seem to remember how to split an array into two parts. In my code, I want to split the array and print its contents from let's say myArray[a] to myArray[b] as the first column, and then myArray[c] to myArray[d] in the second column. Can anyone help me with this?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 602 Times in 517 Posts

    Default Re: Splitting an Array?

    How would you do this "by hand" without any code? Given a stack of index cards, how would you lay them out in two rows?

    Assuming you're not using a GUI, keep in mind that there's probably no way to print a column, then print another column next to it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Char array to a String array with hex
    By fortune2k in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2014, 12:01 PM
  2. reading content of the text file, splitting it into strings
    By Dodo in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: January 6th, 2011, 06:57 PM
  3. prininting out a 4x4 array according to an order by a 1d array
    By fortune2k in forum Collections and Generics
    Replies: 7
    Last Post: November 25th, 2010, 11:54 AM
  4. 2d (4x4) array insdie a 1d array. (Block cipher)
    By fortune2k in forum Collections and Generics
    Replies: 13
    Last Post: November 23rd, 2010, 04:29 PM
  5. Splitting File into Array
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 3rd, 2010, 10:48 AM