# another random java question



## RedWizard (Jan 15, 2007)

Hello.

=]

I have been experimenting with for loops, and nested loops. In this application I enter and bowling scores for 2 players and get an average. In this example I have 2 players with 2 scores.

The issue I am having is keeping track of the *accumulative average*. As you can see I cannot discover an effective method of doing this

This application will calculate the average of 2 games for 2 bowling players, however I can not discover how to make it display the total average.

*/
import javax.swing.*;
public class Bowlers
{
public static void main(String[] args)
{
final int bowlerscores = 2; //define number of games as 3
final int threebowlers = 2; //establish the amount of bowlers as 3

int A,B; 
double temptotalavg, totalaverage, score, total, average;
String s1;
//this line begins the first loop. the outter loop.
for (A = 1; A <= threebowlers; A++) 
{
total = 0; 
for (B = 1; B <= bowlerscores; B++) 
{
s1 = JOptionPane.showInputDialog(
"Enter Score of Bowler:");
 score = Double.parseDouble(s1);
total = total + score; 
} 
average = total / bowlerscores; 
*totalaverage = ??????*
JOptionPane.showMessageDialog(null, 
"The average for bowler # " + A + " is " + average,
"Mike's Nested Loop Average Bowl Application", 
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, 
"Therefore; as of yet the accumulative average is " + totalaverage,
"Mike's Nested Loop Average Bowl Application", 
JOptionPane.INFORMATION_MESSAGE);

} // end of the outer for loop
System.exit(0);
} 
}

If anyone could help me understand how to do this (without using any if statements or additional nests) i'd be much obliged..

Thanks again

-RedWizard


----------



## Chicon (Jul 29, 2004)

*totalaverage = ((totalaverage * (A-1)) + average) / A*


----------



## RedWizard (Jan 15, 2007)

i appreciate your assistance chicon.

=]


----------



## Chicon (Jul 29, 2004)

RedWizard said:


> i appreciate your assistance chicon.
> 
> =]


Thanks, RedWizard ! :up:


----------

