# Problem with getting the average

Page 1 of 1

## 3 Replies - 199 Views - Last Post: 02 February 2018 - 05:50 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=409078&amp;s=e01e611111f756865ef1b9f8cfff99cf&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kaendria01

Reputation: 0
• Posts: 2
• Joined: 02-February 18

# Problem with getting the average

Posted 02 February 2018 - 05:15 PM

I have a problem. I made a program that asks the user to enter three scores. The program returns the average grade but doesn't display the average. So what am I doing wrong that I can't get the average?

```import java.util.Scanner;

public class TestScores {
public static void main (String[] args) {

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter the first Score");
String score1;
score1 = keyboard.nextLine();

System.out.print("Enter the second score");
String score2;
score2 = keyboard.nextLine();

System.out.print("Enter the third score");
String score3;
score3 = keyboard.nextLine();

answer = (Integer.parseInt(score1) + Integer.parseInt(score2) + Integer.parseInt(score3) / 3);

System.out.println("The average score is + answer + .  You earned an A.");

System.out.println("The average score is + answer + .  You earned a B.");

System.out.println("The average score is + answer + .  You scored a C.");

System.out.println("The average score is + answer + .  You scored a D.");

else

System.out.println("The average score is + answer + .  You scored an F.");

}
}
```

Is This A Good Question/Topic? 0

## Replies To: Problem with getting the average

### #2 jon.kiparsky

• Beginner

Reputation: 11040
• Posts: 18,852
• Joined: 19-March 11

## Re: Problem with getting the average

Posted 02 February 2018 - 05:37 PM

```System.out.println("The average score is + answer + .  You earned an A.")
```

This is printing the literal line "The average score is + answer + . You earned an A." If you want it to include the value of answer you need to close the quoted portions like so:

```System.out.println("The average score is " +  answer + ".  You earned an A.")

```

In general, it is helpful if you can be more specific about what the problem is. In this case, showing the bad output would have been useful - better still if you included a corrected version showing what you want it to look like. Thanks!

### #3 kaendria01

Reputation: 0
• Posts: 2
• Joined: 02-February 18

## Re: Problem with getting the average

Posted 02 February 2018 - 05:43 PM

That helped me greatly, thank you! But now that I fixed it, it gives me "The average score is 93 You earned an A." When I have put the test scores as all 40's

This post has been edited by ndc85430: 02 February 2018 - 08:59 PM
Reason for edit:: Removed quote of previous post. Please just press "Reply" in future.

### #4 jon.kiparsky

• Beginner

Reputation: 11040
• Posts: 18,852
• Joined: 19-March 11

## Re: Problem with getting the average

Posted 02 February 2018 - 05:50 PM

Consider this line. What is 40 + 40 + 40 / 3? (think about operator precedence)

```answer = (Integer.parseInt(score1) + Integer.parseInt(score2) + Integer.parseInt(score3) / 3);
```