Arrays in a do...while

I have an assignment that will compile, but I need to put an array that will display 6 numbers instead of one. It has to be do..while and I need an array. I am not asking for the solution, just a hint in where code for the array should go. If I am on the right track. Here's what I have:

// bz.java

//

import java.util.Random;

public class bz

{

public static void main( String args[] )

{

Random randomNumbers = new Random();

int startRandomNumbers= 1;

int maxRandomNumber = 56;

do

{

int chooseRandomNumber = startRandomNumbers + randomNumbers.nextInt(maxRandomNumber);

System.out.printf("\n%s%d\n\n","The random number is ",chooseRandomNumber);

}

while (1 >= 56);

} //end main

} //end class

[811 byte] By [wallasongsa] at [2007-11-26 19:53:17]
# 1
You don't need an array at all for that.Are you asking how to fill an array up with the random numbers?
paulcwa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 2

You realize that a do-while is meant to do loops, but

while (1 >= 56);

, there's no point in using the do-while, since that will always be false... use variables, for example

do

print something, increase number of printings by 1

while number of printings < 6

Ruly-o_Oa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 3
I need the array to complete an assignment. The do...while isn' t my idea either.Thanks for the reply!
wallasongsa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 4

Well, yeah, but I find it hard to believe that the assignment just said "hey, just throw an array in there randomly somehow. Cowabunga dude!"

Keep in mind that homework assignments often ask for very specific implementations, or make arbitrary and often bizarre restrictions that you wouldn't do in real life.

Just quote the actual assignment.

paulcwa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 5
Verbatim:Write a program, that uses a do loop, then create six random numbers, from 1 to 56. Load these 6 numbers into a six-element array. Write a do loop to display all of the elements of the array.
wallasongsa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 6
Maybe you can tell us in pseudocode or english how you would do that step by step?
Icycoola at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 7

So you need two do/while loops. First to generate the random numbers and store them in an array. Second one to display the numbers.

declare an array of length 6

loop

generate a random number and store in array

end loop

loop

print out number from array

end loop

floundera at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 8
Flounder , I think you pointed to where I have to look. Thanks for the help! I'm gonna try it from what you gave me! Thanks everyone!
wallasongsa at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 9
I often find that in solving a programming problem, the design part is which satisfy me the most, while optimizing code is second.
Icycoola at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 10

> he design part is which satisfy me the most

Yet this is where most people fail. They are given an assignment and their initial response is "I don't know how to do that". When I was tutoring I often heard students complain how hard Java was. Wrong! It is their inabilty to figure out the algorithm that is their failing. They already know and understand the syntax. This is why 9 times out of 10 the first response people get is "How would you do it on paper?"

floundera at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...
# 11
> Yet this is where most people fail.Then you should get him to practise ;pGuide them bit by bit until they got a "ding" in their head =)
Icycoola at 2007-7-9 22:44:56 > top of Java-index,Java Essentials,New To Java...