我想创建一个程序,给定一对字符串,根据对中提供的长度限制它们或添加额外的字符。例如,它应该表现为:
create (new Line[] {"try","chicken"},
new Couple[] {new Couple(’t’,3),new Couple(’c’,3)})
应该返回
{"try", "chi"}
以上是当长度(指定的数字)小于或等于给定的单词时。下面是一个例子,如果长度大于单词。
create (new Line[] {"try","chicken"},
new Couple[] {new Couple(’t’,3),new Couple(’c’,9)})
应该返回
{"try", "chickenPP"}
也就是说,我们用字母 P 替换剩余的空格。
这是我尝试过的:
import java.util.Arrays;
public class Learn {
private char firstChar;
private int length;
private char chars;
private char FILL_CHARACTER = 'P';
public Learn(char firstChar, int length, char chars) {
this.length = length;
this.firstChar = firstChar;
this.chars = chars;
}
public static String[] create(String[] first, Couple[] second) {
String[] strings = new String[first.length];
for (int i = 0; i < first.length; i++) {
if (second.length = first.chars) {
learns[i] = first[i];
} else if (second.length > first.chars) {
learns[i] = first[i] + FILL_CHARACTER;
}
}
}
}
如您所见,我有很多错误。我想我可能对 API 感到困惑。请帮我改正。