dimanche 26 mars 2017

If/else statement, else is printing everytime

I'm writing a code and everytime I run it, the else statement always prints with the if statement. I've looked it over a ton and I can't figure out what's wrong. Any help would be appreciated. Thanks! Here is the code

import java.util.Scanner;

public class TextMsgAbbreviation {
   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      String userText = "";

      System.out.println("Input an abbreviation: ");
      userText = scnr.nextLine();

      if (userText.equals("LOL")) {
         System.out.println("laughing out loud");
      }

      if (userText.equals("IDK")) {
         System.out.println("I don't know");
      }

      if (userText.equals("BFF")) {
         System.out.println("best friends forever");
      }

      if (userText.equals("IMHO")) {
         System.out.println("in my humble opinion");
      }

      if (userText.equals("TMI")) {
         System.out.println("too much information");
      }

      else {
         System.out.println("Unknown");
      }

      return;
   }
}

Aucun commentaire:

Enregistrer un commentaire