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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:04:13+00:00 2026-05-25T14:04:13+00:00

Possible Duplicate: String comparison in Java heres my script: public class euler4 { /**

  • 0

Possible Duplicate:
String comparison in Java

heres my script:

public class euler4 {

    /**
     * a palindromatic number reads the same both ways. the largest palindrome
     * made from the product of 2-digit numbers is 9009 = 91 * 99.
     * 
     * find the largest palindrome made from the product of two 3-digit numbers.
     */
    public static void main(String[] args) {
        /*for(int t = 100; t < 200; t++) {
            for(int l = 100; l < 100; l++) {
                String milah = "" + t * l;
                String result = palin(milah);
                if(result != "no_pali") {
                    System.out.println(milah);
                }
            }
        } */
        String result = palin("abba");
        System.out.println(result);
    }

    public static String palin(String the_num) {
        int orech = the_num.length();
        String back_word = "";
        /**
         * the for loop has the counter starting at the orech of the number, then
         * decrementing till 0 (or the 0'th index)
         */
        for(int i = orech - 1; i >= 0; i--) {
            back_word = back_word + the_num.charAt(i);
        }
        System.out.println(the_num);
        System.out.println(back_word);
        System.out.println(back_word == "abba");
        if(back_word == the_num) {
            return back_word;
        } else {
            return "no_pali";
        }

    }
}

at line 34 it prints “abba” like it should

at line 35 it prints an exact copy of “abba” like it should

it gets weird at line 36 which is:

System.out.println(back_word == "abba");

and that prints false…..??

it printed exact copy of the words, but when i compare them, it gives false!?

and since they dont equal (when they really do) its returning the wrong thing

  • 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-25T14:04:14+00:00Added an answer on May 25, 2026 at 2:04 pm

    In java the == operator compares the address of the object.

    To compare if two strings are equals you need to use the .equals() function.

    back_word.equals("abba");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: String equality vs equality of location public class AboutStrings{ public static void
Possible Duplicate: Java string comparison? I have encounter the following problem, I have an
Possible Duplicate: Java string comparison? I was trying to do this: boolean exit =
Possible Duplicate: How do I compare strings in Java? String s1 = andrei; String
Possible Duplicate: java String concatenation How to Improve performance of this chunk of code
Possible Duplicate: What makes reference comparison (==) work for some strings in Java? I
Possible Duplicate: How do I compare strings in Java? why first comparison ( s1
Possible Duplicate: Case insensitive string comparison in C++ C++ count and map How to
Possible Duplicate: C#: String.Equals vs. == Are string.Equals() and == operator really same? sometimes
Possible Duplicates: String comparison and String interning in Java What is the difference between

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.