# Thread: Average of numbers in output.

1. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

## Average of numbers in output.

I have written this code

Java Code:
```for (int rolls = 0; rolls < 30; rolls++) {

int value = (int)(Math.random() * 6 + 1);

System.out.print(value + " ");```
And it produces this output: 5 3 4 6 4 2 2 2 5 2 3 3 1 2 3 5 3 1 1 6 1 1 6 1 3 4 6 6 5 3

Now I need to find the average of my 30 dicerolls, and print that out aswell. Can anyone help me?

2. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Average of numbers in output.

Start with defining for yourself in plain English how you calculate the average mathematically without any code, then translating that to Java code should be trivial.

3. ## Re: Average of numbers in output.

pseudo code is a great place to start, but when translating don't forget about the scope of your variables

Scope tutorial
Last edited by Huskies; 09-11-2013 at 05:03 PM.

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Average of numbers in output.

Uh, you're linking to the JNDI tutorial here. That ain't exactly the best read for a novice :)

5. ## Re: Average of numbers in output.

whoops still had the other one in the clip board! thanks

6. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Average of numbers in output.

Don't like that new link very much to be honest, but perhaps it is helpful.

7. Member
Join Date
Sep 2013
Posts
2
Rep Power
0

## Re: Average of numbers in output.

Thank you for all the tips's's's. I've finished my task now :)