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,427
  • 7
  • 31
  • 59
Brian Var
  • 5,808
  • 22
  • 104
  • 200

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
  • 35,277
  • 7
  • 46
  • 71