I have a programming homework. It says that I need to reverse the string first, then change it to uppercase and then remove all the whitespaces. I actually did it, but our professor didn't say anything about using replaceAll()
method. Is there any other way to do it beside replaceAll()
?
Here is my code:
public static void main(String[] args) {
String line = "the quick brown fox";
String reverse = "";
for (int i = line.length() - 1; i >= 0; i--) {
reverse = reverse + line.charAt(i);
}
System.out.println(reverse.toUpperCase().replaceAll("\s", ""));
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…