regg jones wrote:I have to use the != because I need to make sure the code checks that pigword doesn't equal to end. If I use the equal method, I won't be able to run the code in my while loop.]
Paul Clapham wrote:... Use the equals() method instead -- and the ! operator if you want not-equals.
Paul Clapham wrote:I don't understand the while-loop in the solve() method. There's nothing in that method which can change the pigword variable to "end", so the while-loop can only run at most once.
Surely that means that is an infinite loop and it will never terminate. Actually, as you suggested, one shouldn't have a loop inside the method; one should have the method call inside a loop.Please avoid \n and \r; despite what you see in many books, they don't necessarily give the correct platform‑specific line ends. I don't think you need a line end there anyway.Paul Clapham wrote:. . . . There's nothing in that method which can change the pigword variable to "end", so the while-loop can only run at most once. . . . .
Mike Simmons wrote:Based on that description, my concern would be that it would be stuck in an infinite loop, rather than running at most once. But there is also a return within the method, allowing the method to complete.
I missed that: sorry.Mike Simmons wrote:. . . there is also a return within the method . . . .
Paul Clapham wrote:Your while-loop covers lines 7, 8, 9, and 10. It repeats those lines until something changes the value of the variable pigword to "end". Now, which of those lines changes the variable?
regg jones wrote:I have changed my code a bit more and now I cannot seem to figure out a way to make the number variable equal to the scanner input. Here's my code.
regg jones wrote:ut now I want to make int number= 0 and also = scan3.nextInt()