You are not logged in. Please login at www.codechef.com to post your questions!

×

solution to question, that how to reverse the string from any point, in java

To print any type of string in this order example " My Name Is" output should be in this format " yM emaN sI" every word in the string has to be reversed individually.

asked 16 Sep, 15:09

avikshit123's gravatar image

0★avikshit123
1
accept rate: 0%


According to me, if you a reversing a string from a certain point, you could assign it to a char[] array and run two decrementing loops. If you want to reverse each word separately, read from the console using scanner.next() and reverse individual word using char[] array.
You could also refer to this link: https://stackoverflow.com/questions/7569335/reverse-a-string-in-java

link

answered 16 Sep, 17:05

arnavvarshney's gravatar image

2★arnavvarshney
585
accept rate: 20%

Please accept the answer, if it was helpful!

(12 Oct, 16:20) arnavvarshney2★

Well, if you are using java

If you are sure that words are broken by only having space between them, you can use following idea...

String s = your string

String[] ar = s.split (" ");

String out = "";

For(int i=0; i < ar.length; i++){

Out += new StringBuilder (ar [i]).reverse ().toString () + " ";

}

System.out.printlnt (out);

In C++, you can add each word to a vector and then run a loop on teachhis vector, running a backward loop on each word and appending to output string...

Please UPVOTE and Accept this answer if you find this helpful......

link

answered 16 Sep, 17:46

taran_1407's gravatar image

5★taran_1407
2.1k521
accept rate: 22%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,064

question asked: 16 Sep, 15:09

question was seen: 138 times

last updated: 12 Oct, 16:20