0% found this document useful (0 votes)
41 views1 page

Java Exercise 15

This Java class contains a method called multiString that takes a string and integer as parameters. The method repeats the input string the number of times specified by the integer and returns the concatenated string. It iterates from 0 to the length, adding the input string and separator to a variable which is returned at the end.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Java Exercise 15

This Java class contains a method called multiString that takes a string and integer as parameters. The method repeats the input string the number of times specified by the integer and returns the concatenated string. It iterates from 0 to the length, adding the input string and separator to a variable which is returned at the end.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 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);
}

You might also like