0

The program is supposed to be a user inputting his chosen category, but when I tried running it, I typed "African", the command on the else statement appeared.

package finalProject;

import java.util.Scanner;

public class Lol {
    static String category;

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

        System.out.println("Welcome to Shang-ri La Plaza Mall Restaurant Inquiry! \n");
        System.out.println("Choose from below which cuisine do you prefer. \n" +
            "African or American");
        category = x.next();

        if (category == "African") {
             System.out.println("Options are found below with their corresponding price range. \n" +
                 "Wendy's Hamburger - P199 & Below");
        } else {
             System.out.println("Options are found below with their corresponding price range. \n" +
                 "Clawdaddy's Great American Picnic - P500 - P999 \n" +
                 "California Pizza Kitchen - P200 - P499 \n" + 
                 "Tender Bob's - P200 - P499 \n" +
                 "Steak Escape - P200 - P499 \n" +
                 "Balboa - P200 - P499 \n" +
                 "Billy Rock Bar & Restaurant - not found \n" +
                 "Clawdaddy Osteria Americana - P500 - P999 \n" +
                 "Gourmet To Go - P200 - P499 \n" +
                 "Maple - P500 - P999 \n" +
                 "Quiznos - P200 - P499 \n" +
                 "Texas Roadhouse Grill - P500 - P999");
        }
    }
}
Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108

2 Answers2

3

Try using

if (category.equals("African") { 

Never, ever (ever) use == when comparing strings. That will test for object equality and not content (see How do I compare strings in Java?).

Community
  • 1
  • 1
Jens Egholm
  • 2,730
  • 3
  • 22
  • 35
0

use

category.equals("African");

you are comparing string values

Encyclopedia
  • 134
  • 1
  • 9