Shengbo Gao Shengbo Gao - 2 years ago 109
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);


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download