Question: This is in Java being run through Eclipse. /** * Given two strings of the same length, returns the index at which the * strings

This is in Java being run through Eclipse.

/** * Given two strings of the same length, returns the index at which the * strings first differ. If the strings are equal the function should * return -1. * * For example: * firstDifference("abc", "axy") returns 1 * firstDifference("aby", "abz") returns 2 * firstDifference("foo", "bar") returns 0 * firstDifference("ninja", "ninja") returns -1 * firstDifference("","") returns -1 * * You don't need to worry about inputs of different lengths. * * Hint: if you want to compare the two strings to see if they * are equal. For example, something like this: * * if(one.equals(two)) return -1; * * Individual characters however, should be compared with == * char a = one.charAt(0); * char b = two.charAt(0); * if(a == b) { * System.out.println("First characters are equal"); * } * * Requires: for loops or while loops, strings */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!