私はユーザーが入力した各ボウラーの平均ボウリングスコアを計算して表示するプログラムを書いています。 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
ヒント:コードに括弧を自由に振ってください。 –