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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:31:18+00:00 2026-06-18T00:31:18+00:00

for(i=0;i<m1.length();i++) for(j=0;j<m2.length();j++) if(m1.charAt(i)==m2.charAt(j)){ intersection=intersection+m1.charAt(i); m2.charAt(j)=’ ‘; } System.out.println(intersection); } while(devam==false); } } that’s my

  • 0
         for(i=0;i<m1.length();i++)
             for(j=0;j<m2.length();j++)
                 if(m1.charAt(i)==m2.charAt(j)){
                     intersection=intersection+m1.charAt(i); 
                     m2.charAt(j)=' ';



                 }

                    System.out.println(intersection);



         } while(devam==false);

    }

}

that’s my code. and we are not allowed to use a method or an array, we are just beginners.my code gives an error at the point of m2.charAt(j)=' ';. i wrote that line because, when we find an intersection, we shouldn’t check that element again.can you please help?

  • 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-18T00:31:20+00:00Added an answer on June 18, 2026 at 12:31 am

    You cannot modify the content of a String with

    m2.charAt(j)=' ';
    

    Do this instead

    m2 = m2.replace(m2.charAt(j), ' ');
    

    Note that replace() will replace the first character in the string equal to the first parameter. I assume that, since the string represent a set, will not be repeated characters. If there are and you want to replace all of them, just use replaceAll() instead.

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

Sidebar

Related Questions

for(int i=0;i<number.length();i++){ if(number.charAt(i)==0){ nums[i]=11; System.out.println(bob); }else{ nums[i]=number.charAt(i); } } I am trying to get
This code is inside the main function: Scanner input = new Scanner(System.in); System.out.println(Type a
I accidentially typed in \s instead of , while(cname.charAt(cname.length-1) == \s) Aren't special characters
I have a variable length array of strings declared in javascript that contains Dungeons
Firstly apologises for the length of code but I wanted to show it all.
Does the length of the CommandText of an SqlCommand make a difference? I'm not
for (int i = 0; i < s.length(); ++i) { if (s.charAt(i) >= 'A'
for (var i=a.length-1;i>0;i--) { if (i!=a.indexOf(a.charAt(i))) { a=a.substring(0,i)+a.substring(i+1); } } I found this in
I have the following code public static int unknown(String x) { if ((x.length()==1) &&
I'm using eclipse IDE, and sometimes, depending on the code, System.err output is printed

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.