33,028
社区成员
发帖
与我相关
我的任务
分享
public class reverse {
/**
* @param args
*/
public static void main(String[] args) {
String s = "I am a student";
int j = s.length()-1;
for(int i = s.length()-1;i>=0;i--)
{
char c;
if((c=s.charAt(i))!=' ' && (i!=0))
{
continue;
}
else
{
for(int k = i+1;k<=j;k++)
{
System.out.print(s.charAt(k));
}
if(i == 0)
{
System.out.print(s.charAt(0));
}
System.out.print(" ");
j = i-1;
}
}
}
}