0

I'm taking in a numeric input from a user using the scanner class. But after the calculation has completed I want to return to the initial prompt for input.

//get user input 
Scanner user_input = new Scanner(System.in);
String fibMaxNum;

System.out.println("Enter the highest fibonacci number: ");
fibMaxNum = user_input.next();

Does anyone know how I can acheive this in code?

I've tried to return the control to the initial input by adding a return statement but this has no effect.

Madhawa Priyashantha
  • 9,208
  • 7
  • 28
  • 58
Brian J
  • 5,416
  • 19
  • 94
  • 189

1 Answers1

1

Try something like:

do {
    System.out.println("Enter the highest fibonacci number: ");
    fibMaxNum = user_input.next();
    if (fibMaxNum < 0) break;
    //process fibMaxNum.
} while (true);
SMA
  • 33,915
  • 6
  • 43
  • 65