// Use StringBuilder for string concatenation in loops.
package string;
public class StringTest
{
public static String padChars1(int n, String orig)
{
String result = "";
for (int i = 0; i < n; i++)
{
result = result + orig;
}
return result;
}
public static String padChars2(int n, String orig)
{
StringBuilder result = new StringBuilder("");
for (int i = 0; i < n; i++)
{
result = result.append(orig);
}
return result.toString();
}
public static void main(String[] args)
{
System.out.println(padChars1(10, "*"));
System.out.println(padChars2(10, "*"));
}
}
댓글 영역