Hi guys, I'm stuck on the following simple problem. Method 1 asks for input. Method 2 gets input and checks it against a criterion - if it fails, we start back at method 1, if it passes, we finish. But it doesn't work - if the input fails the test the first time around, it gets stuck in a loop where the new input isn't recognised. I'm really struggling with understanding why/how this is happening, and I'd be eternally grateful if somebody could help me.
As an example, if the user inputs a value less than 10, the program goes back to Method 1, BUT, if they then enter a (valid) number greater than 10 the system still goes back to Method 1 - it doesn't exit. I suspect it has something to do with using the while loop - I understand I can use an if statement instead, but I want to understand why it fails with the while loop. Any feedback appreciated.
Cheers,
Al.
import java.util.Scanner; public class TESTINGCODE { public static void main(String[] args) { Method1();} public static void Method1(){ System.out.println("Enter an integer greater than 10"); Method2();} public static void Method2(){ Scanner input = new Scanner(System.in); int value = input.nextInt(); while(value < 10){ Method1(); } } }