Java. Implement a method that will return a String with an array's elements separated by spaces. The mehod will recieve three parameters: the integer array, a start index, and an end index. Both start and end are includive. The method's signature is as follows: public static String printRange(int [], int, int) - make the method public to faciliate testing - If the indexes are outside the bounds of the array, the method should return "Invalid Range." Otherwise, the method will return a String containing one integer after the other on the same line separated by one space. Example 1: Given {4,1,2,36,6}, 1, 3 as the parameters; the method should return "1 2 36" Example 2: Given {4,1,2,36,6}, 0, 7 as the parameters; the method should return "Invalid Range"
Java.
Implement a method that will return a String with an array's elements separated by spaces. The mehod will recieve three parameters: the integer array, a start index, and an end index. Both start and end are includive.
The method's signature is as follows:
public static String printRange(int [], int, int)
- make the method public to faciliate testing -
If the indexes are outside the bounds of the array, the method should return "Invalid Range." Otherwise, the method will return a String containing one integer after the other on the same line separated by one space.
Example 1: Given {4,1,2,36,6}, 1, 3 as the parameters; the method should return "1 2 36"
Example 2: Given {4,1,2,36,6}, 0, 7 as the parameters; the method should return "Invalid Range"
Trending now
This is a popular solution!
Step by step
Solved in 2 steps