Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: home work ..

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default home work ..

    hey all how are you ?

    a little problem I have , well I have to make an array which generates 50 numbers from 0 to 999 which I can manage that the problem lies with the part were the numbers generatet cant be the same here is what ive done so far
    import java.util.Random;
    public class ArrayRandom{
    	public static void main(String args[]
    		{
    			Random r = new Random();
    			int temp;
    			int arr[] = new int[50];
    			for(int i = 0; i < 50; i++)
                            {
     
                            temp = r.nextInt(999) + 1; // this will give you a random number between 0 to 999.
     
                            arr[i] = temp; //here we know that the number is unique, so we can put it inside arr[i]
                            }
                            for(int i = 0; i < 50; i++)
                            {
                                   System.out.print(arr[i] + " ");
                            }
                    }
     
     
    }


    if some one could help me this would be a great help thanx shane : )


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: home work ..

    Since this is homework, you're probably not allowed to use classes and methods available in the standard API which might make this easier.

    Think how you would do this without a computer. Say you have a sheet of paper ruled with 50 lines. You call a friend and ask him/her to give you a number between 0 and 999. How do you decide whether that number can be written into the next blank line or has to be rejected because it's a duplicate? How do you know when to stop calling friends for more numbers?

    Oh, and random.nextInt(999) doesn't give you a random number between 0 to 999. Read the API more carefully, paying special attention to the words inclusive and exclusive.

    db

  3. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    shane1987 (November 7th, 2010)

  4. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts
    Last edited by Darryl.Burke; November 7th, 2010 at 05:24 PM.

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: home work ..

    What, are you here to help or to point out cross posters? :

  7. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: home work ..

    Quote Originally Posted by javapenguin View Post
    What, are you here to help or to point out cross posters? :
    To point out cross posters. Why does that bother you?

    db

  8. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: home work ..

    Well, I've cross posted on this forum before because I got impatient and days went by with no response. Also, I often update posts and the forum only shows original post dates, not edit post dates, as the last post date.

    Also, it almost seems that you're spending more time reporting cross posters than you are asking for and/or giving help.

    That's all.

    Also, found spam at http://www.javaprogrammingforums.com...urse-java.html

  9. The Following User Says Thank You to javapenguin For This Useful Post:

    shane1987 (November 16th, 2010)

  10. #8
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: home work ..

    Quote Originally Posted by javapenguin View Post
    Also, it almost seems that you're spending more time reporting cross posters than you are asking for and/or giving help.
    You don't think pointing out cross posts helps the forum regulars?

    All help in a thread needn't be directed at the OP.

    db

  11. #9
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: home work ..

    HTML Code:
    import java.util.Random;
    
    Public class ArrayRandom3
    {
      public static void main(String[] args)
        {
            Random r = new Random();
            int array[] = new int[50];
            int a = 0;
            while (a < 50)
            {
              
                int random = r.nextInt(999);
                array[a] = random;
    
                // **********************
                //  make sure the numbers arnt the same here 
                //   
                // **********************
                                                 
                
            a++;
            }
            int i = 0;
                for(int row = 0; row< 10; row++)
                {
                				for(int c = 0; c<=4; c++)
                				{
                				System.out.format("%03d ", array[i]);
                				i++;
                				}
                System.out.println("");
                }                        
            
        }
    }
    ok guys ive done most of the code but i cant do the loop to make sure the numbers in the array are not the same can you help me now?
    Last edited by shane1987; November 16th, 2010 at 02:46 PM.

Similar Threads

  1. Long term project work from home developer
    By internext in forum Paid Java Projects
    Replies: 17
    Last Post: May 2nd, 2012, 08:51 PM
  2. How to Get users home directory
    By JavaPF in forum Java Programming Tutorials
    Replies: 0
    Last Post: September 2nd, 2010, 11:37 AM
  3. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 11:24 AM
  4. my run program does not work
    By rman27bn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 16th, 2009, 10:13 AM
  5. Why won't this while loop work?
    By trueblue in forum Loops & Control Statements
    Replies: 2
    Last Post: July 17th, 2009, 10:10 AM