you're stuck on the loop...
what loop? you haven't got a single line of code, let alone a block of code with a loop in it.
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
[Making sure I understand]
You need to create a lotto program where the user tries to match a 6-digit number (or string) such as "123456".
If the user matches at least three digits (in any order) in the string there is a winning message.
If the user matches all 6 digits, a jackpot message is displayed.
[Repeating numbers]
Are you saying that:
1) Repeating numbers are to be ignored
or
2) Repeating numbers are not allowed?
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
for(int i=0; i f.length :)
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
f is an array, so you will need to read them individually.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
You must decide if you want the numbers all at once or one at a time.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
You'll probably end up with a lot more code than you think.
You will need to compare the two arrays to see if they match.
You will need to compare one array against itself to make sure there are no repeating numbers (in my world).
You will also need to set a guage to determine what is (and is not) winning.
I also like to use descriptive variable names, so I don't forget what they are later on and so I never have to guess their type.
like:
//////////////////////////////////////////////////////////////////////////
// Repeating numbers don't make sense and will not be tolerated ;)
if(hasRepeatingNums(arr_intUserGuess))
{
System.out.println("That entry has repeating numbers and is invalid");
return;
}
...where I can tell the question being asked is if there are repeating numbers in an array of integers that are what the user guessed.
Of course, you'd need to make the hasRepeatingNums function.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
So, keep in mind: if you know how to make functions, do so.
Each different element of this could/should be broken out into a different function -- that way, you can
1) keep your project straight and manageable
2) be able to REUSE solutions for problems you've already solved
3) avoid contaminating proven solutions by accident or bad design
With that said, think about how you would use something like this:
/////////////////////////////////////////////////////////////////////////////
// Returns the number of matches in two arrays of integers
// Duplicates will skew the results, so use arrays with no duplicates.
private static int getNumMatches(int[] a, int[] b)
{
int intNumMatches = 0;
for(int i=0; i < b.length; i++)
{
for(int j=0; j < a.length; j++)
{
if(b[i] == a[j])
{
intNumMatches++;
}
}
}
return intNumMatches;
}
Even if you don't immediately understand what it'sdoing, you can tell what it does.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
just a minor remark:
this check:
if(freq>= 0 && freq <= 2){
can be replaced by
if(freq <= 2){
you're just running a check you've already ran in your first if statement :)
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433