vendredi 22 janvier 2021

String Task: write a program that asks the user enter a three letter word. Please help :) [duplicate]

Please explain what is going on =(

Task: write a program that asks the user enter a three letter word. Check if the middle character of the given word is 'a'. In the case it is print: "Cool word", but in the case the middle letter is not 'a' print: "Okay word". - If the user does not enter a 3 letter word tell them: If the word is less than 3 letters: "Word is too short" - If the word is too long: "Word is too long"

public class StringTask_Clone {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("Enter three letter word");
        String word = input.next();

        if (word.length() == 3) {
         else if (word.charAt(1) == "a") {
                System.out.println("Cool word");
            } else {
                System.out.println("Okay word");
            }

        } else (word.length()> 3) {

            System.out.println("Word is too long");
        }
         else(word.length()<3){
        
            System.out.println("Word is too short");
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire