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);
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.
String str = "Welcome Java";
char[] strArray = str.toCharArray();
for (int i = strArray.length-1; i >=0 ; i--) {
System.out.print(strArray[i]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.