Comparing Each Character in Java String
Posted
by
user2760357
on Stack Overflow
See other posts from Stack Overflow
or by user2760357
Published on 2013-10-19T01:09:39Z
Indexed on
2013/10/19
3:55 UTC
Read the original article
Hit count: 167
I am a beginner at java, and I am trying to create two strings and compare each character.
If there is a matching character or characters, the code has to print out the length of each string, without the matching characters.
For example, if one string is "super," and the other is "perfect," the program should interpret the strings as superfect, and print out 9
However, if there is no matching part, like pencil and eraser, the code should printout 12, which is the length of two strings combined.
Right now, I am having a problem with comparing each character, since I tried to use
if(input_word.compareToIgnoreCase(input_word2) != 0)
but it only compared the string as a whole..
any suggestion?
Thank you for your efforts
© Stack Overflow or respective owner