In Java, I am creating a program that asks the user to think of someone they know.
Then, my program asks that they enter the first letter of their first name, and the last letter of their last name, with no spaces.
I want my program to then look through an array of whole names, find the one whose first letter matches the first letter of user input, with the corresponding last letter of their last name.
here is my program so far:
import java.util.* ;
public class Guesser
{
public static void main(String[] args)
{
Scanner UserInput = new Scanner(System.in);
String [] names = {"firstname lastname " + "etc"}; //example name array
System.out.print( "Hello! I am a robot. I might be smart, but I don't know. Please play a game with me to help me see if I am smart." + "\n" + "What I want you to do is think of someone you know." + "\n" + "Enter the first letter of their first name, and the last letter of their last name. Please no spaces. Then, press enter. " );
String TheirGuess = UserInput.nextLine(); //get their input, assign a string to it
System.out.println("You entered: " + TheirGuess);
char FirstChar = TheirGuess.charAt(0); // get the the first char
char SecondChar = TheirGuess.charAt(1); // get the second char
System.out.println("I will now think of someone whose first name starts with " + FirstChar + " and last name ends with " + SecondChar );
UserInput.close();
}
}
How would I search in my string array for a name that has FirstChar as the first character and SecondChar as the last char?