考虑这段代码:
public static void main (String[] args) {
String name = "(My name is Bob)(I like computers)"
StringReader s = new StringReader(name);
try {
// This is the for loop that I don't know
for () {
String result = "";
// Here the char has to be appended to the String result.
}
System.out.println("The string is: " + result);
} catch (Exception e) {
e.toString();
}
}
我正在寻找的是一个 for 循环,它首先查看当前位置的字符,然后如果该字符不是“)”,则将其附加到字符串中。但是,字符“)”也应该附加到字符串中。在此示例中,输出应为:
字符串结果是:(我的名字是 Bob)