A static method called middlechar that takes a string


1. A static method called middleChar that takes a String object as a parameter and returnsthe character (a value of type char) in the "middle" of the string. If the string has an odd number of characters, the method should return the actual middle character. If the string has an even number of characters, there are two characters that could both be considered middle characters, and your method should return the first of these characters (the one closer to the beginning of the string). For example:

> Methods.middleChar("clock")
'o'
> Methods.middleChar("Boston") 
's'

This method should not do any printing; rather, it should extract the appropriate character and return it.

2. A static method called moveToEnd that takes as its two parameters a string str and an index i and returns a new string created by "moving" the first i characters of str to the end of the string, after the other characters in str. If the string str has i or fewer characters, the method should simply return the original string. For example:

> Methods.moveToEnd("Boston", 4)
"onBost"
> Methods.moveToEnd("Terriers", 2)
"rriersTe"
> Methods.moveToEnd("Boston", 8)
"Boston"

You may assume that the value of i is positive. This method should not do any printing; rather, it should return the appropriate string

Assume the class name is Methods

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: A static method called middlechar that takes a string
Reference No:- TGS02641843

Now Priced at $20 (50% Discount)

Recommended (91%)

Rated (4.3/5)