Click to See Complete Forum and Search --> : Help with for loop


hammackr
09-10-2005, 05:29 PM
I have a for loop that counts down from 35 to 20.
for(count=3; count>=20; count--)
I have a public variable int numberThirtyfive=35

Initially I need to display the results, 4 numbers to a line.

after I display the results I need to get a sum total of all of the numbers and display it.

Then I need to get an average of all of those numbers and display it.

Can anyone help

Khalid Ali
09-11-2005, 08:04 AM
this is how you can do this..

1. declare some variables to be used in this process such as,
String partialDisplay="";
int numToDisplay = 4;
int sumOfNums = 0;

2. run a loop such as for(int x=35;x>=20;x--)
3. in the loop use the modulous (%) operator to find out if there are 4 numbers in line.
if( (x%numToDisplay)==0){
//display partialDisplay here
partialDisplay ="";
}else{
partialDisplay+=x+",";
sumOfNums +=x;
}


something like the above should help