本帖最後由 蔡庭豪 於 2018-9-2 00:02 編輯
- package com.example.houyang.triangle;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- TextView first;
- TextView second;
- TextView third;
- TextView res;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- first = findViewById(R.id.first);
- second = findViewById(R.id.second);
- third = findViewById(R.id.third);
- res = findViewById(R.id.result);
- }
- public void triangle_judge (View view){
- int a = Integer.valueOf(first.getText().toString());
- int b = Integer.valueOf(second.getText().toString());
- int c = Integer.valueOf(third.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||b*b+c*c>a*a)
- res.setText("鈍角三角形");
- else if(a*a+b*b<c*c||a*a+c*c<b*b||b*b+c*c<a*a)
- res.setText("角三角形");
- else if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
- res.setText("直角三角形");
- else if(a==b && b==c && a==c)
- res.setText("三角形");
- else
- res.setText("無法溝成三角形");
- }
- public void Clear(View view){
- first.setText(" ");
- second.setText(" ");
- third.setText(" ");
- res.setText(" ");
- }
- }
複製代碼 |