1) Reverse each word in a string Input: hello world java
//Output: olleh dlrow avaj
String str="hello world java";
String[] tokens=str.split(" ");
for(int i=0;i<tokens.length;i++) {
for(int j=tokens[i].length()-1;j>=0;j--) {
System.out.print(tokens[i].charAt(j));
}
System.out.print(" ");
}
0 comments:
Post a Comment