public class MainActivity extends AppCompatActivity {
EditText num1,num2;
TextView result;
Button add,sub,mul,div;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 = findViewById(R.id.number1);
num2 = findViewById(R.id.number2);
result = findViewById(R.id.myresult);
add = findViewById(R.id.addBtn);
sub = findViewById(R.id.subBtn);
mul = findViewById(R.id.mulBtn);
div = findViewById(R.id.divBtn);
add.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
int a = Integer.parseInt(num1.getText().toString());
int b = Integer.parseInt(num2.getText().toString());
int sum = a + b;
result.setText(String.valueOf(sum));
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
int a = Integer.parseInt(num1.getText().toString());
int b = Integer.parseInt(num2.getText().toString());
int sub = a - b;
result.setText(String.valueOf(sub));
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
int a = Integer.parseInt(num1.getText().toString());
int b = Integer.parseInt(num2.getText().toString());
int quo = a / b;
result.setText(String.valueOf(quo));
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
int a = Integer.parseInt(num1.getText().toString());
int b = Integer.parseInt(num2.getText().toString());
int pro = a * b;
result.setText(String.valueOf(pro));
}
});
}
}
ANDROID STUDIO APP-DEV | SIMPLE COMPUTATION OF TWO NUMBERS
Reviewed by Gin Florita
on
January 05, 2020
Rating:
No comments: