所以我想做的是返回:
输入是createMixedString(Hello,there,3)
我想输出HellothereHellothereHellothere
我的问题是,当它运行时,它只返回 Hellothere
,就好像程序没有看到我在 for 循环中所做的重新分配。
public static String createMixedString(String s1, String s2, int n) {
String result = s1+s2;
for (int i=0;i>=n;i++) {
result = result+s1+s2;
}
return result;
}
最佳答案
你的 for 条件是错误的,它应该是 i < n ,如下所示:
public static String createMixedString(String s1, String s2, int n) {
String result = s1+s2;
for (int i=0; i < n; i++) {
result = result+s1+s2;
}
return result;
}
关于Java - 从 for 循环返回信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9169775/