66 926
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #19556 in Java | JSP | JSF for Alex

Question #19556
How can I compare two strings a character at a time and have it return string 1 if more than one letter is different?
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions