我正在编写一个程序,计算并显示用户输入的每个投球手的平均保龄球分数。 我在计算3分数的平均数时遇到了麻烦,现在我认为它是计算分数的总和。我如何使它所以它计算分数的平均Java如何计算3个保龄球分数的平均值
public static void main (String [] args)
{
//local constants
//local variables
String bowler = "";
int total = 0;
int average = 0;
int score1 = 0;
int score2 = 0;
int score3 = 0;
/******************** Start main method *****************/
//Enter in the name of the first bowler
System.out.print(setLeft(40," Input First Bowler or stop to Quit: "));
bowler = Keyboard.readString();
//Enter While loop if input isn't q
while(!bowler.equals("stop"))
{
System.out.print(setLeft(40," 1st Bowling Score:"));
score1 = Keyboard.readInt();
System.out.print(setLeft(40," 2nd Bowling Score:"));
score2 = Keyboard.readInt();
System.out.print(setLeft(40," 3rd Bowling Score:"));
score3 = Keyboard.readInt();
if(score1 >= 0 && score1 <= 300 && score2 >= 0 && score2 <= 300 && score3 >= 0 && score3 <= 300)
{
total += score1;
total += score2;
total += score3;
System.out.println(setLeft(41,"Total: ")+ total);
average = score1 + score2 + score3/3;
System.out.println(setLeft(41,"Average: ") + average);
}
else
{
System.out.println(setLeft(40,"Error"));
}
输入和输出你得到截至目前什么平均? – notyou
如果我为每个分数输入20,它表示平均值是46,不知道为什么 – user8723490
提示:在代码中大量地使用圆括号。 –