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()];
  }

provide some sample input and output
for your program

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.