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 :
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