public class TEst {
/**
* @param args
*/
public static void main(String[] args) {
char[] chs = { '1', '2', '3', ' ', '4', '5', '6', ' ', '7', '8', '9','\n'};
System.out.println(chs);
reverserword(chs);
System.out.println(chs);
}
private static void reverserword(char[] chs) {
int a = 0, b = 0;
char temp;
for (int i = 0; i < chs.length; i++) {
if (chs[i]==' '||chs[i]=='\n'||i==chs.length-1) {
for (int j = a; j < b; j++) {
if(j<(a+b)/2){
temp = chs[j];
chs[j] = chs[b - j + a-1];
chs[b - j + a-1] = temp;
}
}
a = b+1;
b++;
} else {
b++;
}
}
}
}