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);
答案 0 :(得分:3)
假设您已复制并粘贴该块和代码,则错误是因为System.out.print(rev);
已放置在main()
功能块之外。
答案 1 :(得分:0)
String str = "Welcome Java";
char[] strArray = str.toCharArray();
for (int i = strArray.length-1; i >=0 ; i--) {
System.out.print(strArray[i]);
}