I couldn't run the code you have submitted because the variable fixed isn't declared and i suspect the line
fixed; += names.replaceAll(toreplace[i+1],toreplace[i]);
is supposed to be
fixed += names.replaceAll(toreplace[i+1],toreplace[i]);
because that would somewhat explain why you are getting multiple sentences, since you are replacing things multiple times and adding the result to fixed.
That being said I have noticed that when you are replacing the names with
names.replaceAll(toreplace[i+1],toreplace[i]); you should be doing
names.replaceAll(toreplace[i],toreplace[i+1]); since you would like to replace John for Joe, Robert for Bob and Elizabeth for Liz, not the other way around (Joe for John). Basically you want to replace the "even" with the "odd" so if you are selecting the even values of i you you like to replace those with i+1.
Also when iterating the array in the for loop with
for (int i = 0; i <= toreplace.length/2; i++)
you should be doing
for (int i = 0; i <= toreplace.length; i++)
because you want all the "evens" not just half of them, i think you might have switched up yourself a bit here with the evens logic and replacing half...
So to make your code work like you intend to you should replace the following lines:
for (int i = 0; i <= toreplace.length/2; i++) for
for (int i = 0; i <= toreplace.length; i++)
fixed; += names.replaceAll(toreplace[i+1],toreplace[i]); for
fixed = fixed.replaceAll(toreplace[i+1],toreplace[i]);
and also define the variable fixed beforehand Sting fixed = names; so that it has the same value as names.
Furthermore you can also improve your code a little bit:
A for is constituted by three statements for(statement1; statement2; stament3)
statement1 is executed a single time before the code block (what's inside the for)
statement2 defines the condition for executing the code block, the for will run while this statement is true
statement3 is executed everytime after the code block has been executed by the for loop
Generaly you will find and write foor loops like for(i=0; i!=foo; i++) where statement1 is used for variable initialization, statement2 for condition and statement3 for increment, but that doens't mean it is all you can do with it, in reality you can write whatever you want/need in those statements.
In you case you have
for (int i = 0; i <= toreplace.length/2; i++) {
if (i % 2 == 0) { //take even values
fixed; += names.replaceAll(toreplace[i+1],toreplace[i]);
}
}
This means you are iterating over the toreplace array, taking the "evens" and replacing them with the "odds" on the fixed string, however inside the for loop you are selecting only half of the iterations you are making with if (i % 2 == 0) and you don't really need to do that since you can just choose to iterate by 2 instead of iterating all of them and only selecting half of them to do the replacement.
To do this you simply declare for (int i = 0; i != toreplace.length; i+=2) or the long way i=i+2 if you prefer, and you no longer need the if statement because you know you will be iteraing over all the even numbers.
Hope this helped you in some way.