i am trying to generate a random element out of an array. I have assigned the array to reference variable s1, i have declared a random r1 and know to use a fore loop with the array length but I cant use the reference variable in the fore loop . any when I use the the original array studentArray its empty.
When you post code, there are some things you can to do make it easier to read, which in turn makes it more likely someone will be willing and able to help you.
UseCodeTags(←click). I've added them for you in your initial pots.
Don't use so much whitespace, and be consistent in how you do use it. A single blank line between methods, or between logical sections within a method is usually sufficient. I've cleaned up some of that for you as well.
Use consistent indentation. 2 or 4 spaces, not tabs. I didn't try to touch that hot mess.
Post everything needed to demonstrate your problem, and nothing that's not needed. That is, an SSCCE(←click). There's a lot of code there that's not relevant to your problem. Even though it's not clear to me what your actual problem is, I guarantee you don't need all that code to demonstrate it.
I know this may sound like I'm just nitpicking unimportant stuff instead of helping you, but believe me, clearly and precisely communicating your problem so that it's easy for folks here to understand it is paramount if you want help.
So, can you explain a bit more clearly what you're having trouble with, and provide a more concise code sample to demonstrate it?
I agree with Jeff on all points. I tried to answer the question anyway, but couldn't.
kevin cash wrote:I have assigned the array to reference variable s1, i have declared a random r1 and know to use a fore loop with the array length but I cant use the reference variable in the fore loop .
I see a couple places where you declare a Random r1, but I don't see any attempt to use r1 in a for loop. It should be possible, so if it's not working for you, show us what you're doing that's not working.