Re: Help with assignment.
For a local variable you must give a initialization value before you can use it. For example for your loop condition check you can give it an initial value like:
Code:
boolean correct = false;
while (!correct) {
...
}
Re: Help with assignment.
Hello and welcome to java-forums.org!
I think that you may be over-complicating your solution a little since Scanner can check what type of input is available with its hasNextXXX() methods. So exceptions may not be necessary to solve this. One possible solution in "pseudo-code" is:
Code:
Ask for int input
loop: while scan's next input is NOT an int
use the Scanner to get the next line and do nothing with it.
Tell that they again need to enter an int
end of loop
get int from Scanner and use it.
Re: Help with assignment.
Quote:
Originally Posted by
Fubarable
Hello and welcome to java-forums.org!
I think that you may be over-complicating your solution a little since Scanner can check what type of input is available with its hasNextXXX() methods. So exceptions may not be necessary to solve this. One possible solution in "pseudo-code" is:
Code:
Ask for int input
loop: while scan's next input is NOT an int
use the Scanner to get the next line and do nothing with it.
Tell that they again need to enter an int
end of loop
get int from Scanner and use it.
Thanks I made it work ! :)
Re: Help with assignment.