[240] Problem Solving with Strings 題目

Part 3: Problem Solving with Strings

This assignment will give you additional practice using String methods.
You will write two methods to solve some problems using strings and a third method to test these two methods.Specifically, you should do the following:

  • 1.Create a new Java Class named Part3 in the StringsFirstAssignments project.
    Put the following methods in this class.

  • 2.Write the method named twoOccurrences that has two String parameters named stringa and stringb.
    This method returns true if stringa appears at least twice in stringb, otherwise it returns false.
    For example, the call twoOccurrences(“by”, “A story by Abby Long”) returns true as there are two occurrences of “by”, the call twoOccurrences(“a”, “banana”) returns true as there are three occurrences of “a” so “a” occurs at least twice, and the call twoOccurrences(“atg”, “ctgtatgta”) returns false as there is only one occurence of “atg”.

    1. Write the void method named testing that has no parameters. This method should call twoOccurrences on several pairs of strings and print the strings and the result of calling twoOccurrences (true or false) for each pair.
      Be sure to test examples that should result in true and examples that should result in false.
[240] Problem Solving with Strings 題目_第1张图片
螢幕快照 2017-08-14 下午4.03.20.png
[240] Problem Solving with Strings 題目_第2张图片
螢幕快照 2017-08-14 下午5.48.09.png

你可能感兴趣的:([240] Problem Solving with Strings 題目)