1. Member
Join Date
Oct 2010
Posts
4
Rep Power
0

## 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

-------

2. 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. Senior Member
Join Date
Oct 2010
Location
Germany
Posts
787
Rep Power
9
and how does your code look like? what ideas do you have?

4. Member
Join Date
Oct 2010
Posts
4
Rep Power
0
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. Member
Join Date
Oct 2010
Posts
4
Rep Power
0
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

6. Senior Member
Join Date
Oct 2010
Location
Germany
Posts
787
Rep Power
9
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?

#### Posting Permissions

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