Shengbo Gao Shengbo Gao - 6 months ago 23
Java Question

Why is there error on System.out.print(rev);?

public static void main(String[] args) {
// TODO Auto-generated method stub

String rev = "";
String input = "Hello World";
int length = input.length();
for (int i = length - 1; 1 >= 0; i--){

rev = rev + input.charAt(i);

}
System.out.print(rev);

Answer

Assuming you've copy and pasted that block and code, the error is because System.out.print(rev); has been placed outside the main() function block.