I am writing a code which tends to reverse a string as follows:
public class Main {
public static void main(String[] args) {
String str1;
str1 = "This text is waited to be reversed.";
char letters[];
for(int i = str1.length() - 1; i >= 0; i--) {
System.out.print(letters[i]);
}
}
}
But at run-time, system shows that
"Main.java:9: error: variable letters might not have been initialized
System.out.print(letters[i]);
^
1 error"
I cannot get this point. Can anyone explain it for me? Thank U very much!