Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot convert from char to string

String org = "Welcome";
String rev = "";

for (int i = org.length()-1; i >= 0; i--) {
    rev = rev+org.charAt(i);
}
System.out.println(rev);

What does this line mean? = rev+org.charAt(i);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It is a statement to add to the variable rev the character in org at i position. Because you are doing this in a loop, it incrementally adds character in position i.

So iterations becomes :

rev = ""  + e --> resulting in e
rev = "e" + m --> resulting in em
rev = "em" + o --> resulting in emo
rev = "emo" + c --> resulting in emoc
rev = "emoc" + l --> resulting in emocl
rev = "emocl" + e --> resulting in emocle
rev = "emocl" + W --> resulting in emocleW
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading