I am looking for feedback on a solution to the following problem posed from a book that I'm working through (Java: How To Program, 9th Edition):
Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be derived from the letters of that word. For example, the three-letter words produced from the word "bathe" include "ate," "bet," "tab," "hat," "the," and "tea."
I have a sneaking suspicion that I've over complicated things. Is my code easy to understand? I'm a rookie coder still going over the basics.
import java.util.Scanner;
public class ThreeLetterStrings {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner( System.in );
System.out.println( "Please enter a five letter word" );
String userInput = sc.nextLine(); // get input
int wordLength = userInput.length(); // get length of string in question
char[] charArray = new char[ wordLength ];
int stem = 0; // stem being the 2nd letter after the first - b(a)the or ba(t)he
int scan = 0; // scan count for while loop
boolean stamp;
for( int i = 0; i < charArray.length; i++ ) // feed string into char array
{
charArray[ i ] = userInput.charAt( i );
}
for( int startLetter = 0; startLetter < wordLength; startLetter++ )
{
for( int stemLetter = 1; stemLetter < wordLength; stemLetter++ )
{
stem = startLetter + stemLetter;
if( stem >= wordLength )
stem = stem - wordLength;
scan = 0; // reset scan count after walk for loop
for( int walk = 0; walk < wordLength - 2; walk++ )
{
System.out.printf( "%c", charArray[ startLetter ] );
System.out.printf( "%c", charArray[ stem ] );
stamp = false; // determines whether a character was printed
while( stamp == false )
{
if( scan == startLetter || scan == stem )
{
scan++;
}
else
{
System.out.printf( "%c", charArray[ scan ] );
stamp = true;
System.out.println();
scan++;
}
} // end while
} // end walk for
} // end stemLetter for
} // end startLetter for
}
}