String Reverse
-
Hi , I am just trying to reverse all the words of a string at their place only ex if there is a string : "vandana is a good girl" then the out put of the program should be "anadnav is a doog lrig" for that i have created a package to calculate the no of words in the string and also for calculating reverse of a string that pacage is: package p1; public class meth { public int cal(String s) { int wrd=0; for(int i=0;i=0) { for(int i=0;i
-
Hi , I am just trying to reverse all the words of a string at their place only ex if there is a string : "vandana is a good girl" then the out put of the program should be "anadnav is a doog lrig" for that i have created a package to calculate the no of words in the string and also for calculating reverse of a string that pacage is: package p1; public class meth { public int cal(String s) { int wrd=0; for(int i=0;i=0) { for(int i=0;i
-
Why make it so complicated? Just read the string and then loop through the characters in reverse order and print each one. You will end up with the string reversed.
-
i need to reverse the spelling of words and need not to change their order i.e dog is an animal out should be: god si na lamina .if i use for loop then then the whole string get it'sreverse.
-
i need to reverse the spelling of words and need not to change their order i.e dog is an animal out should be: god si na lamina .if i use for loop then then the whole string get it'sreverse.
-
Then all you need to do is split the string at each wordbreak (e.g. space) and then do the same to each word.
-
As I suggested earlier, it can be simplified considerably by using the
Scanner
class, as in the following sample. If you do not wish to use the scanner, then you could write your own class that splits a string into a collection of tokens.public static void main(String\[\] args) throws Exception { Scanner sc = new Scanner("Cotta and Balbus love the sweet voices of the girls"); while (sc.hasNext()) { String nextWord = sc.next(); char c; for (int i = nextWord.length() - 1; i > -1; --i) { c = nextWord.charAt(i); System.out.print(c); } System.out.print(" "); } System.out.println("."); }
-
Hi , I am just trying to reverse all the words of a string at their place only ex if there is a string : "vandana is a good girl" then the out put of the program should be "anadnav is a doog lrig" for that i have created a package to calculate the no of words in the string and also for calculating reverse of a string that pacage is: package p1; public class meth { public int cal(String s) { int wrd=0; for(int i=0;i=0) { for(int i=0;i