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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started