TIPOS DE ESTRUCTURAS REPETITIVAS DE PROGRAMACION
package com.example.ciclos;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText edtnum, edtcant;
TextView tvres;
Button btn;
ImageButton btnsalir;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtnum = (EditText) findViewById(R.id.edtnum);
edtcant = (EditText) findViewById(R.id.edtcant);
tvres = (TextView) findViewById(R.id.tvres);
btn = (Button) findViewById(R.id.btn);
btnsalir = (ImageButton) findViewById(R.id.btnsalir);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int num = Integer.valueOf(edtnum.getText().toString());
int cant = Integer.valueOf(edtcant.getText().toString());
String acum = "";
for (int i = 1; i <= cant; i++) {
acum += String.format(edtnum.getText().toString() + "X" + i + "=" + (num * i) + "\n");
}
tvres.setText(acum);
}
});
btnsalir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
Comentarios
Publicar un comentario