Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
976 B
1
Indexable
Never
package com.example.unitconverter;

import androidx.appcompat.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 cm;
    Button b;
    private TextView m;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cm=findViewById(R.id.editTextText3);
        m=findViewById(R.id.textView3);
    }
    public void convertcm(View v)
    {
     String cma=cm.getText().toString();
     if(!cma.isEmpty())
     {
         double a=Double.parseDouble(cma);
         double b=a/100;
         m.setText(String.format("Length in meters:%.2f",b));

     }
     else
     {
         m.setText("Please enter a valid length");
     }
    }
}
Leave a Comment