Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:28:22+00:00 2026-06-03T00:28:22+00:00

Ok I am trying to make this simple thing but it won’t work. I

  • 0

Ok I am trying to make this simple thing but it won’t work. I am a beginner in Java and would like some help. Every time I run the code below I get the output That is not a valid option. What am I doing wrong?

 package test;

 import java.util.Scanner;

 public class options {
     public void options() {
         Scanner scnr = new Scanner(System.in);
         String slctn;

         System.out.println("What would you like to do?");
         System.out.println("a) Travel the expedition");
         System.out.println("b) Learn more about the expedition");

         slctn = scnr.nextLine();
         if (slctn == "a"){
             travel exeTravel = new travel();
             exeTravel.travel();
         }else if (slctn=="b"){
             learn exeLearn = new learn();
             exeLearn.learn();
         }else{
             System.out.println("That is not a valid option");
         }
     } 
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:28:24+00:00Added an answer on June 3, 2026 at 12:28 am

    Well, first off, == is a fundamental operator in the language. The result type of the expression is a boolean. For comparing boolean types, it compares the operands for the same truth value. For comparing reference types, it compares the operands for the same reference value (i.e., refer to the same object or are both null). For numeric types, it compares the operands for the same integer value or equivalent floating point values. See the Java Language Specification.

    In contrast, equals() is an instance method which is fundamentally defined by the java.lang.Object class. This method, by convention, indicates whether the receiver object is “equal to” the passed in object. The base implementation of this method in the Object class checks for reference equality. Other classes, including those you write, may override this method to perform more specialized equivalence testing. See the Java Language Specification.

    The typical “gotcha” for most people is in using == to compare two strings when they really should be using the String class’s equals() method. From above, you know that the operator will only return “true” when both of the references refer to the same actual object. But, with strings, most uses want to know whether or not the value of the two strings are the same — since two different String objects may both have the same (or different) values.

         slctn = scnr.nextLine();
         if (slctn.equals("a")){
             travel exeTravel = new travel();
             exeTravel.travel();
         }else if (slctn.equals("b")){
             learn exeLearn = new learn();
             exeLearn.learn();
         }else{
             System.out.println("That is not a valid option");
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying to make this IF statement work, but I can't seem to
This maybe some simple silly thing but I can't figure it out on my
I am trying to make a simple alarm. in this code portion a take
I'm trying to make this fragment work: Version History --------------- These are the versions
I've been trying to make this calendar_date_picker to work for more than two days,
I'm trying to make a simple website using mvc but I'm a little confused
After wasting two days with this question (and trying to make it work), I've
I've been driving myself crazy trying to make this work. Variations of my attempt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.