- package com.example.student.myapplication;
- 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 MainActivity extends AppCompatActivity {
- private EditText et_a,et_b,et_c;
- private TextView tv;
- private Button bt1,bt2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- et_a= (EditText) findViewById(R.id.editText1);
- et_b= (EditText) findViewById(R.id.editText2);
- et_c= (EditText) findViewById(R.id.editText3);
- tv= (TextView) findViewById(R.id.textView);
- bt1= (Button) findViewById(R.id.button);
- bt2= (Button) findViewById(R.id.button2);
- bt1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- double a=Double.parseDouble(et_a.getText().toString());
- double b=Double.parseDouble(et_b.getText().toString());
- double c=Double.parseDouble(et_c.getText().toString());
- if(a+b>c && a+c>b && b+c>a){
- if (a*a+b*b==c*c || a*a+c*c==b*b || c*c+b*b==a*a){
- tv.setText(R.string.tv1);
- }
- else if(a*a+b*b<c*c || a*a+c*c<b*b || c*c+b*b<a*a){
- tv.setText(R.string.tv3);
- }
- else {
- tv.setText(R.string.tv2);
- }
- }
- else{
- tv.setText(R.string.tv4);
- }
- }
- });
- bt2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- et_a.setText("");
- et_b.setText("");
- et_c.setText("");
- tv.setText("");
- }
- });
- }
- }
複製代碼 |