title: How to emulate a do-while?
body: <p>Help solve the problem.
  the first part of the code works, the selection is made, but when typing &quot;exit&quot; - an error</p>
  <pre class="lang-java prettyprint-override"><code>exit
  Exception in thread &quot;main&quot; java.lang.NumberFormatException: For input string: &quot;exit&quot;
      at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
      at java.base/java.lang.Integer.parseInt(Integer.java:668)
      at java.base/java.lang.Integer.parseInt(Integer.java:786)
      at Main.main(Main.java:139)
  
  Process finished with exit code 1
  </code></pre>
  <p>Code:</p>
  <pre><code>import java.util.Scanner;
  
      public class Main {
          public static void main(String[] args) {
              String camel = &quot;&quot;&quot;
              Switching on the camera in the camel habitat...
               ___.-''''-.
              /___  @    |
              ',,,,.     |         _.'''''''._
                   '     |        /           \\
                   |     \\    _.-'             \\
                   |      '.-'                  '-.
                   |                               ',
                   |                                '',
                    ',,-,                           ':;
                         ',,| ;,,                 ,' ;;
                            ! ; !'',,,',',,,,'!  ;   ;:
                           : ;  ! !       ! ! ;  ;   :;
                           ; ;   ! !      ! !  ; ;   ;,
                          ; ;    ! !     ! !   ; ;
                          ; ;    ! !    ! !     ; ;
                         ;,,      !,!   !,!     ;,;
                         /_I      L_I   L_I     /_I
              Look at that! Our little camel is sunbathing!&quot;&quot;&quot;;
  
              String lion = &quot;&quot;&quot;
              Switching on the camera in the lion habitat...
                                                             ,w.
                                                           ,YWMMw  ,M  ,
                                      _.---.._   __..---._.'MMMMMw,wMWmW,
                                 _.-&quot;&quot;        '''           YP&quot;WMMMMMMMMMb,
                              .-' __.'                   .'     MMMMW^WMMMM;
                  _,        .'.-'&quot;; `,       /`     .--&quot;&quot;      :MMM[==MWMW^;
               ,mM^&quot;     ,-'.'   /   ;      ;      /   ,       MMMMb_wMW&quot;  @\\
              ,MM:.    .'.-'   .'     ;     `\\    ;     `,     MMMMMMMW `&quot;=./`-,
              WMMm__,-'.'     /      _.\\      F'''-+,,   ;_,_.dMMMMMMMM[,_ / `=_}
              &quot;^MP__.-'    ,-' _.--&quot;&quot;   `-,   ;       \\  ; ;MMMMMMMMMMW^``; __|
                         /   .'            ; ;         )  )`{  \\ `&quot;^W^`,   \\  :
                        /  .'             /  (       .'  /     Ww._     `.  `&quot;
                       /  Y,              `,  `-,=,_{   ;      MMMP`&quot;&quot;-,  `-._.-,
                      (--, )                `,_ / `) \\/&quot;&quot;)      ^&quot;      `-, -;&quot;\\:
              The lion is roaring!&quot;&quot;&quot;;
  
              String deer = &quot;&quot;&quot;
              Switching on the camera in the deer habitat...
                 /|       |\\
              `__\\       //__'
                 ||      ||
               \\__`\\     |'__/
                 `_\\   //_'
                 _.,:---;,._
                 \\_:     :_/
                   |@. .@|
                   |     |
                   ,\\.-./ \\
                   ;;`-'   `---__________-----.-.
                   ;;;                         \\_\\
                   ';;;                         |
                    ;    |                      ;
                     \\   \\     \\        |      /
                      \\_, \\    /        \\     |\\
                        |';|  |,,,,,,,,/ \\    \\ \\_
                        |  |  |           \\   /   |
                        \\  \\  |           |  / \\  |
                         | || |           | |   | |
                         | || |           | |   | |
                         | || |           | |   | |
                         |_||_|           |_|   |_|
                        /_//_/           /_/   /_/
              Our 'Bambi' looks hungry. Let's go to feed it!&quot;&quot;&quot;;
  
              String goose = &quot;&quot;&quot;
              Switching on the camera in the goose habitat...
              
                                                  _
                                              ,-&quot;&quot; &quot;&quot;.
                                            ,'  ____  `.
                                          ,'  ,'    `.  `._
                 (`.         _..--.._   ,'  ,'        \\    \\
                (`-.\\    .-&quot;&quot;        &quot;&quot;'   /          (  d _b
               (`._  `-&quot;&quot; ,._             (            `-(   \\
               &lt;_  `     (  &lt;`&lt;            \\              `-._\\
                &lt;`-       (__&lt; &lt;           :
                 (__        (_&lt;_&lt;          ;
                  `------------------------------------------
              The goose is staring intently at you... Maybe it's time to change the channel?&quot;&quot;&quot;;
  
              String bat = &quot;&quot;&quot;
              Switching on the camera in the bat habitat...
              _________________               _________________
               ~-.              \\  |\\___/|  /              .-~
                   ~-.           \\ / o o \\ /           .-~
                      &gt;           \\  W  //           &lt;
                     /             /~---~\\             \\
                    /_            |       |            _\\
                       ~-.        |       |        .-~
                          ;        \\     /        i
                         /___      /\\   /\\      ___\\
                              ~-. /  \\_/  \\ .-~
                                 V         V
              This bat looks like it's doing fine.&quot;&quot;&quot;;
  
              String rabbit = &quot;&quot;&quot;
              Switching on the camera in the rabbit habitat...
                       ,
                      /|      __
                     / |   ,-~ /
                    Y :|  //  /
                    | jj /( .^
                    &gt;-&quot;~&quot;-v&quot;
                   /       Y
                  jo  o    |
                 ( ~T~     j
                  &gt;._-' _./
                 /   &quot;~&quot;  |
                Y     _,  |
               /| ;-&quot;~ _  l
              / l/ ,-&quot;~    \\
              \\//\\/      .- \\
               Y        /    Y
               l       I     !
               ]\\      _\\    /&quot;\\
              (&quot; ~----( ~   Y.  )
              It looks like we will soon have more rabbits!&quot;&quot;&quot;;
  
              String[] animals = {camel, lion, deer, goose, bat, rabbit};
  
              // write your code here
              boolean flag;
              boolean flag1;
  
              Scanner sc = new Scanner(System.in);
  
              do {
                  String isbnPattern = &quot;exit&quot;;
                  final int a = 5;
  
                  String input = sc.next();
                  int inputInt = Integer.parseInt(input);
  
                  flag = input.matches(isbnPattern);
                  flag1 = a &gt;= inputInt;
  
                  if (!flag)
                      if (flag1)
                          System.out.println(animals[inputInt]);
              } while (!flag || flag1);
                  System.out.println(&quot;See you later!&quot;);
      }
  }
  </code></pre>