java - Reversing a String using a for loop -
this question has answer here:
- reverse string in java 33 answers
i want reverse inputted string using loop. have tried following code below. [ full of mistake think.. cause dont know how convert things array or string in problem ]. please me coding here...
public class main extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); textview tv = (textview) findviewbyid(r.id.textview1); edittext input_string =(edittext) findviewbyid(r.id.edittext1); final string orig = input_string.gettext().tostring(); button rev = (button) findviewbyid(r.id.button1); rev.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { int limit = orig.length(); for(int i=limit;i<=limit;i--) { string[] neww = orig[i].; } tv.settext(neww); }}) }}
something you're looking for.
string x = "a string"; string y = ""; for(int = x.length()-1; >= 0; i--){ y=y + x.charat(i); }
your new string stored in variable y.
Comments
Post a Comment