I present three random letters to the user, lets say ' J U D '
and my user has to give a word for each letter starting with the assigned random letter, for example:
"Just Use Data".
I have been unsuccessful searching for how to validate that the user's input starts with the assigned random letter.
My code
public static void generateLetters(){
Random randomLetter = new Random();
int i;
char[] letter = {'A', 'B', 'C', 'D', 'E', 'F'};
// It's A-Z, but for typing sake... you get the point
char[] letters = new char[26];
for(i = 0; i <= 3; i++){
letters[i] = letter[randomLetter.nextInt(26)];
System.out.printf(letters[i] + " ");
}
}
The above block will generate letters randomly and works fine. Below, I'll enter basically what I have for the user input.
public static String[] getWord(String[] word){
System.out.println("Enter a word for your letters: ");
Scanner wordInput = new Scanner(System.in);
String inputWord = wordInput.nextLine().toUpperCase();
return word;
}
Simple thus far and this is my main
function:
public statc void main(String[] args){
generateLetters();
getWord();
}
I need to take the string returned from getWord()
and verify that each word input does begin with the randomly assigned letters. I've been unsuccessful in doing this. All of the syntax I find during my online research just gets me confused.