The purpose of the program is to compare two sentences. If there are different words in the two sentences, mark them.
Train of Thought: Call the split method of string to split the characters, compare them one by one, create a dyeing array, and record the results.
Equals method:
Equals is used to determine whether the strings are the same. First, it determines whether the references of the two objects are the same. If the strings are the same, it does not need to be determined. If they are different, it is necessary to determine whether the content of the strings is the same.
Function parameter passing in Java:
See: http://blog.csdn.net/niuniu20008/article/details/2953785
Result:
Code:
Import java. Io. *; public class test {public static void main (string [] ARGs) throws exception {int color []; string S1 = "I love you! "; System. out. print ("Enter the character:"); bufferedreader BR = new bufferedreader (New inputstreamreader (system. in); string S2 = BR. readline (); // by default, all values are 0 color = new int [s1.split (""). length]; compare (S1, S2, color); For (INT I = 0; I <color. length; I ++) {system. out. println ("A" + I + color [I]) ;}} Private Static void compare (string str1, string str2, int []) {string [] array1 = str1.split (""); string [] array2 = str2.split (""); If (array1.leng Th! = Array2.length) return; else {for (INT I = 0; I <array1.length; I ++) {If (array1 [I]. equals (array2 [I]) {A [I] = 1; system. out. println (I + "equal ");}}}}}