Answer to Question #19556 in Java | JSP | JSF for Alex
2012-11-27T06:31:05-05:00
How can I compare two strings a character at a time and have it return string 1 if more than one letter is different?
1
2012-11-27T06:31:28-0500
public class Test { public static String check(String one, String two) { & boolean equals = false; & for (int i = 0; i < one.length(); i++) { & if (one.charAt(i) != two.charAt(i)) { & equals = false; & } else & equals = true; & } & if (!equals) & return one; & else & return ""; } public static void main(String[] args) { & String one = "string one"; & String two = "string two"; & System.out.print(check(one, two)); } }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment