jeudi 4 novembre 2021

Random numbers who sum add up to predefined number in java

my output contains 3 textfields where when given N value (the doClick() function clicks 3 textfields automatically), then it randomly generates 3 numbers in the three textfields , My code is generating only random numbers , but i want those randomly generated numbers to be exactly add up to given N.

example : when N=20 then possible answers can be:

1.10,10,0 i.e. (textfield1 show 10, textfield2 show 10, textfiled3 show 0, whose sum adds up to given N )

2.15,3,2

3.10,5,5

random numbers can be any positive integer but it should add up to given N.

Any help please.

[here is the part of  the code,][1] [1]: https://i.stack.imgur.com/lKncd.png



Aucun commentaire:

Enregistrer un commentaire