Results 1 to 7 of 7
  1. #1
    MmmDonuts is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Post 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?

    Thanks in advance.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default 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.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default 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. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default 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 :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: Average of numbers in output.

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

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Average of numbers in output.

    Don't like that new link very much to be honest, but perhaps it is helpful.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    MmmDonuts is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: Average of numbers in output.

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

Similar Threads

  1. finding maximum,minimum and average of 10 numbers
    By xxbakugan in forum New To Java
    Replies: 9
    Last Post: 11-02-2012, 10:13 AM
  2. Average of 3 numbers
    By TravisDavis in forum New To Java
    Replies: 3
    Last Post: 10-04-2012, 10:59 PM
  3. Replies: 1
    Last Post: 10-17-2011, 05:58 PM
  4. formatting numbers in output
    By andy3 in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 06:43 PM
  5. Truncating decimal numbers in the output
    By gbade in forum New To Java
    Replies: 2
    Last Post: 11-21-2008, 06:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •