Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import static java.lang.Math.sqrt;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void calc(View v) {
- TextView tv = findViewById(R.id.textView4);
- EditText object_a = findViewById(R.id.editText);
- if (object_a.length() == 0) {
- tv.setText("Try again)");
- return;
- }
- String text_a = object_a.getText().toString();
- double a = Integer.parseInt(text_a);
- EditText object_b = findViewById(R.id.editText2);
- if (object_b.length() == 0) {
- tv.setText("Try again)");
- return;
- }
- String text_b = object_b.getText().toString();
- double b = Integer.parseInt(text_b);
- EditText object_c = findViewById(R.id.editText3);
- if (object_c.length() == 0) {
- tv.setText("Try again)");
- return;
- }
- String text_c = object_c.getText().toString();
- double c = Integer.parseInt(text_c);
- double D = b * b - 4 * a * c;
- System.out.println(D);
- Toast.makeText(this, "D = " + D, Toast.LENGTH_LONG).show();
- // Log.e("D = ", "" + D);
- if (D < 0) {
- // empty set
- tv.setText("Empty set LOL");
- } else if (D == 0) {
- double x = -b / 2 * a;
- tv.setText("" + x);
- } else{
- double x1 = (-b + sqrt(D)) / 2 * a;
- double x2 = (-b - sqrt(D)) / 2 * a;
- tv.setText("" + x1 + " " + x2);
- }
- }
- }
Add Comment
Please, Sign In to add comment