Вы находитесь на странице: 1из 1

Java Exercise 15:

Write a Java class called StringTool with an operation multiString that returns the input string
repeated as a sequence of a specific length. The operation has two input parameters: a string
and an integer that specifies how often the input string should be repeated in the output. The
output is another string that contains the multiple input strings.

Solution:
package bite;

public class stringTool {


public String multiString(String inputString, int length) {
String pre = "";
String lastOp = "";
for (int i = 0; i < length; i++) {
lastOp += pre + inputString;
pre = "; ";
}
return lastOp;
}

public static void main(String[] args) {


stringTool st = new stringTool();
String s = st.multiString("Bite", 6);
System.out.println("The output String is: " + s);
}

Вам также может понравиться