【发布时间】:2013-01-14 16:22:20
【问题描述】:
考虑这段代码:
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 循环,它首先查看当前位置的字符,然后如果该字符不是“)”,则将其附加到字符串中。但是,字符“)”也应该附加到字符串中。在这个例子中,输出应该是:
字符串结果是:(我叫鲍勃)
【问题讨论】:
-
我没问你问题。你想要的是第一个括号之间的子字符串吗?
-
我想查看字符串名称中的每个字符并返回“)”之前的字符串部分。然而,字符“)”也应该在该字符串中。
标签: java string char stringreader