J'ai besoin d'aide avec l'algorithme Je ne comprends pas ce que je fais mal, quand je fais moins, il donne un nombre négatif (pas un bon) et quand je fais plus puis moins le nombre est vraiment vraiment mal, comment puis-je mettre un arrêt après chaque func et comme le fais calculer correctement je l'ai essayé tant à faire que je ne sais pas tout ce que l'algorithme à utiliser im assez nouveau au codageCalculatrice code moins func ne fonctionne pas
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
buttonClear = (Button) findViewById(R.id.buttonClear);
buttonPlus = (Button) findViewById(R.id.buttonPlus);
buttonEquals = (Button) findViewById(R.id.buttonEquals);
buttonMinus = (Button) findViewById(R.id.buttonMinus);
textFinal = (TextView) findViewById (R.id.textFinal);
int resultValue=0;
buttonPlus.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String s = (String) textFinal.getText();
ResultValue = ResultValue + Integer.parseInt(s);
textFinal.setText("");
}
});
buttonMinus.setOnClickListener (
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String s = (String) textFinal.getText();
ResultValue = ResultValue - Integer.parseInt(s);
textFinal.setText("");
}
});
buttonEquals.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String s = (String) textFinal.getText();
ResultValue = Integer.parseInt(s)+ResultValue ;
textFinal.setText(Integer.toString(ResultValue));
ResultValue=0;
}
});
J'ai essayé d'entrer un nouvel int appelé LastAction et de le faire arrêter après une action et de renouveler le calcul. J'ai essayé plus de choses que je ne peux pas oublier.
J'ai essayé:
int LastAction = 0 , and if (LastAction = 1) {
String s = (String) textFinal.getText();
ResultValue = ResultValue - Integer.parseInt(s);
textFinal.setText("");}
LastAction=1;
Quel est votre type de ResultValue? Aussi généralement variable ne commence pas avec une lettre majuscule. –