I'm having a problem swapping two strings in my array. Let's say Array[0] is "Daniel" and Array[1] is "Paul", how do you go about switching them?
This is my code and it just throws a bunch of errors at me.
public void swap()
{
String name1;
String name2;
String temp1;
String temp2;
System.out.print("\nWhich person would you like to swap?: ");
name1 = input.next();
System.out.print("Who are they swapping with?: ");
name2 = input.next();
for (int i = 0; i <= 10; i++)
{
if(seats[i] == name1)
{
temp1 = name1;
temp2 = name2;
name1 = temp2;
name2 = temp1;
return;
}
}
System.out.println(name1 + " and " + name2 + " have been swapped.\n");
}
Any help would be greatly appreciated, thanks in advance.