samedi 1 avril 2017

Random equation generator [duplicate]

This question is an exact duplicate of:

I am trying to build a function which will generate a random equation into a TextView and the user will then have to answer in an EditText. I am new to Android and so far have learnt how to generate two separate integers. I can also make a simple equation but only if I predefine the operator (see below). My goal is to have a new random equation every time the user taps a "Generate equation" button that I have.

private void goGenerate() {

    Random r = new Random();
    int num1 = r.nextInt(10);
    int num2 = r.nextInt(10);
    result = num1+num2;

    // DISPLAY:
    operator = String.valueOf(num1) + " + " + String.valueOf(num2) + " = ?";
    textViewOperation.setText(operator);
}

Any help is appreciated!!




Aucun commentaire:

Enregistrer un commentaire