Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.ifro.estudos;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- EditText edCatetoA, edCatetoB;
- TextView tvResultado;
- int catetoA, catetoB;
- double resultado;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // vinculação de elementos da view com o controlador
- edCatetoA = (EditText) findViewById(R.id.edCatetoA);
- edCatetoB = (EditText) findViewById(R.id.edCatetoB);
- tvResultado = (TextView) findViewById(R.id.tvResultado);
- }
- public void onCalcular(View v) {
- // c² = a² + b²
- catetoA = Integer.parseInt(edCatetoA.getText().toString());
- catetoB = Integer.parseInt(edCatetoB.getText().toString());
- resultado = Math.sqrt(Math.pow(catetoA, 2) + Math.pow(catetoB, 2));
- tvResultado.setText("O valor da hipotenusa é: " + resultado);
- }
- public void onLimpar(View v) {
- edCatetoA.setText("");
- edCatetoB.setText("");
- tvResultado.setText("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement