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 7530601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:57:20+00:00 2026-05-30T04:57:20+00:00

My program must display whether the answer to the question Is 10>2 is correct,

  • 0

My program must display whether the answer to the question “Is 10>2” is correct, wrong or the user must have had wrong input. Even if I type “YES” or “NO”, it will still display WRONG INPUT. It is a very, very simple program. However, I’m a newbie. Any help will be appreciated.

import java.util.Scanner;

public class yesorno{

public static void main (String args[]){

    Scanner answer = new Scanner(System.in);
    String ans;

    System.out.println("Answer with a YES or NO");
    System.out.println("Is 10>2?");
    System.out.print("Answer:");
    ans = answer.next();

    if(ans == "YES"){
        System.out.print("Correct!");
    }

    else if (ans == "NO"){
        System.out.println("Wrong!");
    }

    else{
        System.out.println("Wrong input!");
    }
}
}
  • 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-05-30T04:57:22+00:00Added an answer on May 30, 2026 at 4:57 am
    if(ans == "YES"){
    

    You should use equals() to compare strings and not operator==

    Note that operator== will yield true only if the two objects are actually the same object, and it is not the case.

    You should replace it to if(ans.equals("YES")) { [and do the same for all other conditions in your program]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the need to express simple conditionals as program input. The input must
I have a Android program which you type in equation and them program display
I have lots(+2000) of GUIDs(in some network class) and my program must find one
I have a program that still must target Windows XP (_WIN32_WINNT 0x501), as most
I have program, that must interact with a console program before my program can
I got a question about this program, it says: The FizzBuzz Challenge: Display numbers
im writing a quiz program. if the user is wrong the 1st time, he
I have a Mac OS X program visible only in status bar that must
I have a concurrent server where a user chooses an option to display. Every
I'm using NSMapTable in a program that must run under both 3.0 and 2.2.1.

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.