- package com.example.redabbrf.red;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class RED extends AppCompatActivity {
- EditText editText, editText2, editText3;
- TextView textView;
- Button btn1, btn2;
- double a,b,c;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_red);
- editText = (EditText) findViewById(R.id.editText);
- editText2 = (EditText) findViewById(R.id.editText2);
- editText3 = (EditText) findViewById(R.id.editText3);
- textView = (TextView) findViewById(R.id.textView);
- btn1 = (Button) findViewById(R.id.button);
- btn2 = (Button) findViewById(R.id.button2);
- btn1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- a = Double.parseDouble(editText.getText().toString());
- b = Double.parseDouble(editText2.getText().toString());
- c = Double.parseDouble(editText3.getText().toString());
- if(a+b>c && b+c>a && a+c>b)
- {
- if(a*a+b*b==c*c || c*c+b*b==a*a || a*a+c*c==b*b)
- {
- textView.setText(R.string.ans1);
- }
- else if (a*a+b*b>c*c || c*c+b*b>a*a || a*a+c*c>b*b)
- {
- textView.setText(R.string.ans2);
- }
- else
- {
- textView.setText(R.string.ans3);
- }
- }
- else
- {
- textView.setText(R.string.ans4);
- }
- }
- });
- btn2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- editText.setText("");
- editText2.setText("");
- editText3.setText("");
- textView.setText("");
- }
- });
- }
- }
複製代碼 |