-
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?
-
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.