Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Tyler Haddox
Tyler Haddox
715 Points

Mixing Random numbers with my array in Java

I'm trying to make a "Bulls n Cows" game. I'm getting stuck on mixing my random number generator and my array. I'm trying to make the computer pick a 4 digit number and the user guess what it is. Normally I wouldn't need an array necessarily but when the user enters their number I have to spit back two things: How many numbers exist in the computer's picked numbers. How many are a direct match.

It's a little hard to explain. This is what I would need:

Computer Random 5378 User Input 3218

 Exists        Match
     2            1

The 3 and 8 are both in the computer's secret number (2 exists) but only the 8 has the same place value (1 match). Thus, I need to use an array that uses random numbers to know when there is an 'exists' and an 'match'. On top of all this the numbers randomly generated cannot repeat. Ex. 7755

Hopefully this makes since. Thank you very much for any feedback!

Is this just a side project of yours? if so, I would like to help you out but not on the forums.

Tyler Haddox
Tyler Haddox
715 Points

Actually its one part of a homework assignment in my Programming 1 class. I have many other things to do on this project that I don't know how to do but I feel like this is a major part of it. Any help would be greatly appreciated but why not on the forums?

the forums are fine, it's just that sometimes I don't get notifications when someone has replied. What code do you have so far? Also, does your teacher want you to complete this project a certain way (like any guidelines).