【发布时间】:2020-03-12 13:58:18
【问题描述】:
public static void main(String[] args) {
String name = "Netbeans 8.2";
String output = "";
char charData[] = {};
for (int i = name.length(); i > 0; i--) {
output = name.charAt(i-1) + output;
System.out.println(output);
}
for (int i = name.length(); i < 40; i++) {
output = " " + output;
System.out.println(output);
}
charData = output.toCharArray();
char last = charData[39]; // von char [39]
int j=0;
for (int i = 38; i >= 0; i--) { //somewhere here must be redone to fix the problem, I know where I get wrong.
charData[i + 1] = charData[i];
for (charData[j] = 0; j < 15; j--) {
charData[0] = last;
output = new String(charData);
}
System.out.println(output);
}
}
/*
The expected outcome should be like:
2
.2
8.2
8.2
s 8.2
ns 8.2
ans 8.2
beans 8.2
tbeans 8.2
etbeans 8.2
Netbeans 8.2
Netbeans 8.2
......
(till length 40)
Netbeans 8.2
2 Netbeans 8.
.2 Netbeans 8
8.2 Netbeans
.....
etbeans 8.2 N
*/
最后一个字符一旦移动到右侧并达到数组范围的限制将再次出现在左侧的开头,这意味着我应该使用 for 让其余被吃掉的字符继续出现从每次回收的开始。这是我已经花费了一整天并且无法正确执行的问题。我不熟悉通过'for'方法获取字符串值。
有人有想法吗?万分感激! 感谢您的支持!享受编码!
【问题讨论】:
-
欢迎来到 SO!请阅读minimal reproducible example 并相应地编辑您的帖子。您的代码似乎执行完美,但有问题缺少预期输出和实际输出以及问题的详细说明