Results 1 to 2 of 2
  1. #1
    csanch11 is offline Member
    Join Date
    Oct 2013
    Posts
    47
    Rep Power
    0

    Default Need help on using the .equals() method in netbeans

    This is the body of the program...


    Scanner keys = new Scanner(System.in);
    System.out.print("Enter the first letter... ");
    int s1 = keys.nextInt();
    System.out.println("Enter the second letter... ");
    int s2 = keys.nextInt();

    if (s1.equals(s2)) {
    System.out.print(s1 + " is less than " + s2);
    } else {
    System.out.println(s1 + " is greater than " + s2);
    }


    The "if (s1.equals(s2)) {" part of the program is underlined in red but I don't know why. Anyone know how to fix this? If you need additional information just ask me. Thanks!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Need help on using the .equals() method in netbeans

    ints are primitive values, not objects, so equals doesn't apply. Always compare primitives with == or any other related relational operator.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. What is the use of equals () method?
    By srinivasmallabathula in forum Advanced Java
    Replies: 3
    Last Post: 08-04-2011, 06:57 PM
  2. equals method :::::HELP:::::
    By alihht in forum New To Java
    Replies: 5
    Last Post: 03-09-2010, 08:19 AM
  3. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 08:20 PM
  4. equals method
    By mani_miit in forum Advanced Java
    Replies: 7
    Last Post: 09-09-2009, 11:26 PM
  5. equals method
    By timkd127 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •