• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Java Programming Question

Given 2 strings, a and b, return the number of the positions where they
contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3,
since the "xx", "aa" and "az" substring appear in the same place in
strings.

stringMatch("xxcaazz","xxbaaz") -> 3

stringMatch("abc", "abc") -> 2

stringMatch("abc", "axc") -> 0

public int stringMatch(String a, String b)
{
     write code???
}
0
robdijo
Asked:
robdijo
  • 3
  • 3
1 Solution
 
CEHJCommented:
Post the code you've written and we'll help with it. We don't write classwork for people
0
 
robdijoAuthor Commented:
I do not know where to start.  I have no code.
0
 
CEHJCommented:
Break down the task into parts, starting with

a. obtain all length 2 substrings from the source string by iteration [and print them out]

(the part in brackets can be removed later)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:


Is this your class assignment ?
0
 
for_yanCommented:


Determine the minimum of two lengths,

Math.min(s0.length(), s1.length())

initiate the counter int count = 0;
start the loop from 0 to the index of minimumlength-3

make

if(s0.substring(curindex, currentindex+2).eqiuals(s1.substring(curentindex,curindex+2)))count++

when you exit the loop
your counter will have number of matches

0
 
for_yanCommented:
write the code in this sense - post it we will correct
0
 
CEHJCommented:
>>write the code

No need - you did it for him. Homework done then...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now