Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. If two strings are superimposed on one another, then some letters may match o

ID: 3642583 • Letter: 1

Question

1. If two strings are superimposed on one another, then some letters may match one another. For
example, in the two strings
wonderwhowrotethebookonlove
weallliveinayellowsubmarine
there are three positions that contain the same letter: the first (w), the fourteenth (e), and the twentyseventh
(e). Of 27 possible positions, matches occur in three of them, or 11.1%. This percentage is
called the index of coincidence for two strings. It is more than just a curiosity; during World War II, it
was used to help decrypt enemy ciphers.
Complete the coincidence() method. This method takes two Strings of equal length as its
arguments. The method computes and returns its arguments

Explanation / Answer

public double coincidence(String A,String B) { int n; n=A.length();//assuming that n = B.length as well int same=0; for(int i=0;i