How to can I sum some numbers in a random series?

56 Views Asked by At

I'm trying to make a program that generates random two-digit integers until I get a 10 or a 20. To then find the mount of numbers, the sum of the numbers less than 10, the sum of the numbers equal to 15, the sum of the numbers greater than 70. Can someone help me, please? This is my code:

// Variables
int numRandom = 0, less10, equal15, more70;
    
// Process
txtS.setText("Random numbers: " + "\n");
for (int mountNum = 0; numRandom == 40 || numRandom == 20; mountNum++) {
    numRandom = (int) (99 * Math.random());
    txtS.append(numRandom + "\n");
}
1

There are 1 best solutions below

0
On BEST ANSWER

You could just store the values directly and create variables for each case.

This is an example for you less than 10 case. (The 'if statement' would be contained inside your for loop).

int sumLessThanTen = 0;
int countLessThanTen = 0;
...
if(numRandom < 10){
    sumLessThanTen += numRandom;
    countLessThanTen++
}