Question: Write a program that accepts two different strings and returns the number of characters that are different. Either string can be null, or of any
Write a program that accepts two different strings and returns the number of characters that are different. Either string can be null, or of any length. If one string is null and the other is not, all of the characters are different.
public class Problem20 { public static void main(String[] args) { System.out.println(countDifferences(null, "Tost")); // 4 System.out.println(countDifferences(null, null)); // 0 System.out.println(countDifferences("abcdef", "abddef")); // 1 System.out.println(countDifferences("poolside", "sidepool")); // 8 } public static int countDifferences(String phrase1, String phrase2) { // Your code here } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
