How do you write a method that switch a space " _ " with a letter, the example my teacher gave us to work with is:

public static int seqSwapSearch ( int[] list, int item)
int location = -1;
int temp;
for (int i = 0; i < list.length; i++)
if (list[i] == item)
location = i;
if (i > 0) // can only swap if we are not at first element
temp = list[i-1]; // store the previous element
list[i-1] = list[i]; // overwrite the previous element
list[i] = temp; // overwrite the current element
return location;

but I have to use this method for a string all i could come up with is:

public static String letterSwap()
    String s = secretWord();
    char [] String;
    char temp;
    temp = String[s.charAt(letterGuessing())];
    String[s.charAt(letterGuessing())] = String[letterGuessing()];
7 Years
Discussion Span
Last Post by code learner
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.