Home » Java » How can I get the sum, difference, quotient, product of two values and printed out in textview [on hold]

How can I get the sum, difference, quotient, product of two values and printed out in textview [on hold]

Posted by: admin July 15, 2018 Leave a comment

Questions:

I’m making a simple calculator and I’m having trouble with four basic operations. How do I program it so that when I put one value, then use one of the operations, then put another value, I get the answer?

I’ve tried different solutions but this is the one I’m on right now

        Button btnD = findViewById(R.id.buttonD);
        Button btnM = findViewById(R.id.buttonM);
        Button btnS = findViewById(R.id.buttonS);
        Button btnP = findViewById(R.id.buttonP);

        btnD.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int a = 1;
                int b = 2;
                int q = a/b;
            }
        });
    }
}
Answers: