Okay so i am trying to have something checked without it continuing unless a number doesn't equal any previous numbers. Yet when I run my code it will just continue on. I will show you what I have so far but, I don't know how to fix this. Can someone throw an assist to me? I thought I had this figured out but, I apparently still have errors no matter what.
Java Code:
for (int size = 0; size < 5; ++size)
{
while (noDupes = true) {
System.out
.println("Enter the "
+ place[size]
+ " Powerball number which should be greater than 0 and less than 60");
number = input.nextInt();
if (number > 0 && number <= 59) {
checkNumber(size); //This is the method in question that I keep having problems with. Next Box of Java code shows the actual method
pick[size] = number;
break;
} else {
System.out
.println("Numbers cannot be less than 1 or greater than 59.");
}
}
}
Java Code:
public static void checkNumber(int number) {
for (int k = 0; k < 6; k++)
{
if (number == pick[k])
{
System.out.println("The number you have entered cannot be a duplicate.");
}
else
{
break; //This is the part where I am struggling most at I believe. I don't know if this what
//I need to put in or do I need to put continue or what.
}
}
}
For example I input a 1 for the pick[1] and then on pick[2] I try to enter 1 again but, the program forces me to enter a different number instead. May someone please help me understand this better?
No comments:
Post a Comment