I am trying to create a program in which a user enters a string (which is put into a char array) and then enters a letter and the program checks if the string contains that letter. Here is my code so far:
Scanner keyboard = new Scanner (System.in);
System.out.println("Please enter a word: ");
String input = keyboard.nextLine();
char[] word = input.toCharArray();
Scanner keyboard1 = new Scanner (System.in);
char letter = keyboard1.findInLine(".").charAt(0);
if (word contains letter) { //This is just used as an example of what I want it to do
System.out.println("The word does contain the letter.");
} else {
System.out.println("The word does not contain the letter.");
}
I realize that the condition in the if statement is not valid, I used it just as an example of what I want it to do.
So my question here is: What can I enter in the if statement condition for it to check if the user entered word contains the user entered letter?
Aucun commentaire:
Enregistrer un commentaire