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,633
  • 7
  • 33
  • 60
Brian Var
  • 6,029
  • 25
  • 114
  • 212

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
  • 36,381
  • 8
  • 49
  • 73