Java 按单词倒序输出字符串

来源:互联网 发布:网络学英语哪家好 编辑:程序博客网 时间:2024/06/05 18:12
String str="Hello World";for(j=str.length()-1;j>=0;j--){        c=str.charAt(j);        if(c==' '){            tempString=tempString+c;            tempStr=tempStr+tempString;            tempString="";        }else if(j==0){            tempString=c+tempString;            tempStr=tempStr+tempString;            tempString="";        }else{            tempString=c+tempString;        } } System.out.println(tempStr);
0 0