Assignment operator



public class MainActivity extends AppCompatActivity {

TextView textview;
Button button;
EditText edittext;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = findViewById(R.id.textview);
button = findViewById(R.id.button);
edittext = findViewById(R.id.edittext);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

int x = 3;
int y = 2;

x+=y; // x = x+y
textview.append(" x = "+x+"\n");

x-=y; // x = x-y
textview.append(" x = "+x+"\n");

x*=y; // x = x*y
textview.append(" x = "+x+"\n");

x/=y; // x = x/y
textview.append(" x = "+x+"\n");

x%=y; // x = x%y
textview.append(" x = "+x+"\n");


}
});

}

} 




Comments

Popular posts from this blog

for loop