• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

What am I missing?

What am I missing here?

The idea is to get it to output a particular message depending on the type of letter it is.  So far if I type 'bill' it tells me to pay it but anything else and it goes straight to the last else and types it can't be recognised, even if I type personal, circular or postcard


// Post
import java.util.*;
public class Post
  public static void main (String[]args)
    //create scanner from keyboard
    Scanner myKeyboard = new Scanner (System.in);
    //prompt for letter type
    System.out.print("Please enter the type of letter you have recieved ");
    String type = myKeyboard.nextLine();
    //Determine and display what is to be done with the item
    if (type.equals("bill"))
      System.out.print("This needs to be paid");
    else if (type.equals("circular"))
      System.out.print("This should be thrown away");
    else if (type.equals("postcard"))
      System.out.print("Put this on the wall");
    else if (type.equals("personal"))
      System.out.print("You need to read and reply to this letter");
      System.out.print("I don't recognise that type of letter");

Open in new window

1 Solution
Your code is working perfectly. May be you are mixing with upper/lower cases letter. You can use equalsIgnoreCase() instead of equals() with variable type to overcome the case sensitivity.
flo_the_lil_minxAuthor Commented:
Or maybe I need my eyes testing, I could swear it wasn't working but you're right, it is!

Thanks for looking though, Flo
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now