返回列表 發帖
本帖最後由 蔡庭豪 於 2018-9-2 00:02 編輯
  1. package com.example.houyang.triangle;

  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.TextView;

  6. public class MainActivity extends AppCompatActivity {

  7.     TextView first;
  8.     TextView second;
  9.     TextView third;
  10.     TextView res;
  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_main);

  15.         first = findViewById(R.id.first);
  16.         second = findViewById(R.id.second);
  17.         third = findViewById(R.id.third);
  18.         res = findViewById(R.id.result);
  19.     }

  20.     public void triangle_judge (View view){
  21.         int a = Integer.valueOf(first.getText().toString());
  22.         int b = Integer.valueOf(second.getText().toString());
  23.         int c = Integer.valueOf(third.getText().toString());

  24.         if (a+b>c||a+c>b||b+c>a)
  25.             if(a*a+b*b>c*c||a*a+c*c>b*b||b*b+c*c>a*a)
  26.                 res.setText("鈍角三角形");
  27.             else if(a*a+b*b<c*c||a*a+c*c<b*b||b*b+c*c<a*a)
  28.                 res.setText("角三角形");
  29.             else if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
  30.                 res.setText("直角三角形");
  31.         else if(a==b && b==c && a==c)
  32.             res.setText("三角形");
  33.         else
  34.             res.setText("無法溝成三角形");

  35.     }

  36.     public void Clear(View view){
  37.         first.setText(" ");
  38.         second.setText(" ");
  39.         third.setText(" ");
  40.         res.setText(" ");
  41.     }


  42. }
複製代碼

TOP

返回列表