-2

I just want to reverse a inputted String by using for loop. I have tried the following code below. [ its full of mistake i think.. cause i dont know how to convert things to array or to string in this problem ]. So anyone please help me the 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);
            }}) }}
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Alvin Varghese
  • 1
  • 1
  • 1
  • 6
  • move this `String orig = input_string.getText().toString()` inside button click listener – Raghunandan Aug 07 '13 at 18:30
  • A String is an immutable object that wraps a char array, a String[] is an array of Strings.. – jsedano Aug 07 '13 at 18:30
  • -- Can anyone suggest me the proper coding for that..??? We are taking inputs from the user, so the user may enter long sentences....That also we have to reverse and have to put into textview .. Please.??? – Alvin Varghese Aug 07 '13 at 18:38
  • Anyone else remember a time when we actually did our own homework rather than asking the Internet to do it for us? – gillonba Sep 18 '15 at 19:04

1 Answers1

0

Something like this is what you're looking for.

String x = "A string";
String y = "";

for(int i = x.length()-1; i >= 0; i--){
y=y + x.charAt(i);
}

Your new string will be stored in the variable y.

Zoltorn
  • 171
  • 1
  • 2
  • 10