Results 1 to 3 of 3
  1. #1
    krechlich is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Cool How to count random numbers together?

    Okay, so i have this problem that i need my program to generate 4 random numbers between 2-10 and then count them together. I have already wrote the code which will generate random numbers 4 times, but i don't know how to get them all together...

    Here's my code:
    Java Code:
    package test;
    
    import java.util.Random;
    
    public class Main {
    
        public static void main(String[] args) {
            Random rand = new Random();
            int number;
            
            for (int calculator = 1; calculator <= 4; calculator++) {
                number = 2 + rand.nextInt(9);
                System.out.println(number);
            }
        }
    }
    Thanks to all in advance, i hope someone can write the code for me because i'm really new to java :)

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    int number, sum;
    in your loop sum+= number; ?
    :)

  3. #3
    krechlich is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 10-24-2010, 05:34 PM
  2. use Math.random and then count occurrences
    By iliak67 in forum New To Java
    Replies: 17
    Last Post: 11-16-2009, 05:57 PM
  3. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  4. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  5. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 03:56 AM

Posting Permissions

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