Results 1 to 7 of 7
  1. #1
    M7MD is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default nextint() Method !

    hi all

    i need help in this exercise :)

    develop main method that initializes a random object with the default constructor and then determines the elapsed time for the nextint() method to generate 123456789

    -------

    how :mad:

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Why is this question posted in this section of the forums? I don't see any relation with Threads nor synchronization.

    kind regards,

    Jos

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

    Default

    and how does your code look like? what ideas do you have?

  4. #4
    M7MD is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    sorry i'm new in java and in forums,

    this is my idea
    PHP Code:
     Random r = new Random();
    
     for(int i=1;i<10;i++){
     int Number = r.nextInt(10);
     System.out.println(Number);
    
     }
    this generate random numbers :)

    i need to generate 123456789 using this method

  5. #5
    M7MD is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default

    ok i trying in new idea

    PHP Code:
     Random r = new Random();
    for(int i=0;i<9;i++){
         int[] array=new int[9];
     int Number = r.nextInt(10);
     if((Number==1) || (Number==2) || (Number==3)||(Number==4)||(Number==5)||(Number==6)||(Number==7)||(Number==8)||(Number==9))
             Number=array[i];
     System.out.println(array[i]);
        }
    the output is :

    0
    0
    0
    0
    0
    0
    0
    0
    0


    Why !! :mad::mad:

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

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

    Default

    mhm...maybe i misunderstand the assignment, but i would say you task isnt to generate the 123456789, but only to take the time until the nextInt method generate it?!

    pseudocode:

    Java Code:
    long time = current time;
    generate random numbers with random.nextInt() (without parameters!!) until the number is equal to 123456789
    then --> break
    print current time - time
    that is what the assignment is asking for or?

Similar Threads

  1. Very Bad problem with nextInt()
    By usiyalla in forum New To Java
    Replies: 2
    Last Post: 07-25-2010, 01:44 AM
  2. Replies: 2
    Last Post: 05-23-2010, 11:05 PM
  3. nextInt(unknown source)
    By babyburger in forum New To Java
    Replies: 3
    Last Post: 03-18-2010, 04:03 PM
  4. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 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
  •