-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
  • 24,988
  • 16
  • 102
  • 110
Alvin Varghese
  • 1
  • 1
  • 1
  • 6

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
  • 141
  • 1
  • 2
  • 9