HI guys, I have a text File that Contain Names Starting with the surname and then the First Name. I would Like to read them In a reverse order Starting with the First Name and the Second name. The code I have reads them in the order which they are printed on the text file. For Example
I have the Name:
Mungai Stanley
I want the output to be:
Stanley Mungai
The code I have is:
Give a beggar a fish; feed him for a day. Teach him how to fish; Feed him for a lifetime.
Its not quite difficult as it might sound.
As you already know, array elements can be accessed using the index like
obj[0], obj[1]....,obj[n]
So when you split the read line you get the last name and first name. Just access it as first name(index) and last name(index)
The continuation condition for your for loop looks incorrect.
[edit]I was mistaken, because you are iterating backwards. Joanne was correct. Sorry. You should write
for (int i = myArray.length - 1; i >= 0; i--) ...
[/edit]