【发布时间】:2017-03-31 14:32:13
【问题描述】:
这是我的修改。我正在尝试通过重复 String s 来构建一串 int n 字符。我想要得到的答案是testtestte。
这是我目前所拥有的。当索引达到 4 时,它显然会超出或绑定,因为字符串只有 4 个字符。我想要它,以便当索引达到 3 时它会回到 0 并继续直到 int n 满足(这可能是使用错误的词) 10. 抱歉,如果问题不够清楚。
public static void main(String[] args){
beads("test", 10);
}
public static void beads(String s, int n){
char[] eachChar = new char[n];
for (int index = 0; index < n; index++) {
eachChar[index] = s.charAt(index);
}
System.out.println(eachChar);
}
【问题讨论】: