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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:32:48+00:00 2026-06-12T06:32:48+00:00

I have two strings with me: s1=MICROSOFT s2=APPLESOFT I need to compare the strings

  • 0

I have two strings with me:

s1="MICROSOFT"
s2="APPLESOFT"

I need to compare the strings and remove the duplicate part (always towards the end) from the second string. So I should get “MICROSOFT” and “APPLE” as output.

I have compared both the strings character by character.

               String s1 = "MICROSOFT";
               String s2 = "APPLESOFT";

               for(int j=0; j<s1.length(); j++)
               {
                   char c1 = s1.charAt(j);
                   char c2 = s2.charAt(j);

                   if(c1==c2)
                       System.out.println("Match found!!!");
                   else
                       System.out.println("No match found!");
               }

It should check the strings and if the two strings have same characters until the end of string, then I need to remove that redundant part, SOFT in this case, from the second string. But I can’t think of how to proceed from here.

There can be more duplicates…but we have to remove only those which are continuously identical. if i have APPWWSOFT and APPLESOFT, i should get APPLE again in the second string since we got LE different than WW in between

Can you guys please help me out here?

  • 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-12T06:32:50+00:00Added an answer on June 12, 2026 at 6:32 am

    I have solved my problem after racking some brains off. Please feel free to correct/improve/refine my code. The code not only works for “MICROSOFT” and “APPLESOFT” inputs, but also for inputs like “APPWWSOFT” and “APPLESOFT” (i needed to remove the continuous duplicates from the end – SOFT in both the above inputs). I’m in the learning stage and I’ll appreciate any valuable inputs.

    public class test
        {           
            public static void main(String[] args)
            {
                String s1 = "MICROSOFT";
                String s2 = "APPLESOFT";
    
                int counter1=0;
                int counter2=0;
    
                String[] test = new String[100];
                test[0]="";
    
                for(int j=0; j<s1.length(); j++)
                {
                    char c1 = s1.charAt(j);
                    char c2 = s2.charAt(j);
    
                    if(c1==c2)
                    {
                        if(counter1==counter2)
                        {
                            //System.out.println("Match found!!!");
                            test[0]=test[0]+c2;
                            counter2++;
                            //System.out.println("Counter 2: "+counter2);
                        }
                        else
                            test[0]="";
                    }
                   else
                   {
                       //System.out.print("No match found!");
                       //System.out.println("Counter 2: "+counter2);
                       counter2=counter1+1;
                       test[0]="";
                   }
    
                   counter1++;
                   //System.out.println("Counter 1: "+counter1);
                               }
    
                 System.out.println(test[0]);
                 System.out.println(s2.replaceAll(test[0]," "));
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two strings str1 and str2 . Check both of them and see
I have two strings in a java program, which I want to mix in
I have two strings, one a key and one a value, which I would
I have two strings String s1=426F62; String s2=457665; The strings are in hex representation.
i have two strings in a php i want to make following checks in
If I have two strings that are identical in value, is it guaranteed that
Let's say I have two strings: one is XML data and the other is
Let's say I have two strings like this: XABY XBAY A simple regex that
Lets say that I have two strings: The System is in halt state. The
Let's say I have two same strings inside an ArrayList... is there a way

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.