First, you have to define the problem better. Does 'M' equal 'm'? Some people would say yes, others would say no. Until you define the conditions, there is no point in answering.
Next...please read Campbell's first post. Before you write any code, you should have a good idea how you'd do it using nothing more than paper, pencil, and your brain. Don't even consider writing a single line of code until you can write down in a natural language (English, German, Hindi, Esperanto...) how to do it.
Once you have that, writing the java code (or C, or Perl, or assembly) is almost trivial, assuming your algorithm above is well defined.
So, work on that, and when you have something, post it here, and we'll work on the next steps.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
In case it isn't obvious already, nobody here is going to simply hand you the answer. we're here to help you, not do it for you.
Again, forget about writing a single line of java code. If you didn't have access to a computer, how would YOU find duplicate characters?
Joined: Oct 13, 2005
fred rosenberger wrote: . . . Campbell's first post. . . . paper, pencil, and your brain. . . .
Good grief! Somebody has used "Campbell" and "brain" on the same line.
Joking aside, Ravi Kiran Va, you are mistaken even to write a class name until you know what you plan to do with it. You didn't say you wanted to know how many repeats there are. Go through the Java™ Tutorials section on Collections, and there is an example which does something surprisingly similar to what you want in there somewhere.
First of all, it doesn't really work. The only thing that your code does is find which characters in the string are 'l' or 'L'. Suppose you didn't know beforehand which characters were duplicates - this code would not find them. For example, if I change line 3 to this:
String g = "Mumbai";
then your code would not find the two m's.
Second, you should use the logical OR operator || instead of the bitwise OR operator | in line 6.
Third, line 8 works, but this is not how you should increment the counter: count=++count;
Thanks Jesper de Jong
for your value able points , the code that I wrote was just to show the duplicate character can be find in string , I use static string , now I think I should write that a program that will take string from user and then find the duplicates.
That's too complex. Here is an example in Java, I've tested it. I hope it can be help to you.
Joined: Oct 13, 2005
Welcome to the Ranch
I can see some complex features in your code, too. Changing to lower case and then subtracting to give numbers between 0 and 25 looks complex to me. Also using continue when a simple if is all you need.