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
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.
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
Define help...what do you have so far? If nothing, start here: The Java™ Tutorials
ok i trying in this idea :-
the output is :
0
0
0
0
0
0
0
0
0
Why !! why it not working
When equating two values, the left operand is assigned the value of the right. Inspect your code carefully and you will see that the values within the array are never assigned anything (and thus you print their default value of 0)
M7MD (October 24th, 2010)
Cross posted
nextint() Method ! - Java Forums
db
???????????
!!!!!!!!!!!???????????
That condition is completely unnecessary. The definition of nextInt() is that it will return an integer in the range [0,10). Simply change your random-number generation statement to this and there's no need for an if statement.
int number = r.nextInt(9) + 1; // no need for an if statement, number is guaranteed to be in the range [1,10] array[i] = number; // ...other code
M7MD (October 27th, 2010)
I would do it like this:
Output:
1 2 3 4 5 6 7 8 9
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.
M7MD (October 27th, 2010)