reenadak

2018-12-21_Square-a-number

Dec 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.mukeshdak.squarenumber;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.  
  13.     public void showSquare(View view){
  14.         Log.i("info", "Square Ready");
  15.         EditText et = (EditText) findViewById(R.id.editText1);
  16.         String x = et.getText().toString();
  17.  
  18.         double xd = Double.parseDouble(x);
  19.         double sq = xd * xd;
  20.         String sq_str = String.format("%.2f", sq);
  21.  
  22.         Toast.makeText(this, "Square of " + x + "is " +sq_str, Toast.LENGTH_SHORT).show();
  23.  
  24.  
  25.     }
  26.  
  27.     @Override
  28.     protected void onCreate(Bundle savedInstanceState) {
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.activity_main);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment