对于我们的java类,我们必须使用L allign
,Centered
和R allign.
我已经想出如何将字符串保存到一行,但我不知道如何重置该行。
任何帮助都会很棒!
public static String word(String text, int width) {
String word = "";
String all = "";
String row = "";
String newRow = "";
int textlen = text.length();
for (int i = 0; i < text.length(); i++) {
char current = text.charAt(i);
// works gives a word
do {
if (text.charAt(i) != ' ') {
word += text.charAt(i);
}
i++;
} while (text.charAt(i) != ' ' && i < textlen);
// till here
word += " ";
// System.out.println("this is word: " +word);
while (row.length() < width) {
if (word.length() < width
&& (row.length() + word.length()) < width) {
row += word;
if ((width - (row.length() + word.length())) < 3) {
System.out.println("here is row: " + row);
}
}
if (word.length() > width
&& (row.length() + word.length()) > width) {
}
word = "";
}
row = "";
}
return word;
}
答案 0 :(得分:0)
如果要将String
变量重置为空字符串,只需将其分配给空字符串:
row = "";