Egor_Vakar

TakeInt(Delfi/Java)

Nov 20th, 2021 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. Function TakeInt(Min,Max: Integer): Integer;
  2. var
  3.     IsCorrect: Boolean;
  4.     Number: Integer;
  5. begin
  6.     Number := 0;
  7.     repeat
  8.         IsCorrect := True;
  9.         try
  10.             Readln(Number);
  11.         except
  12.             Writeln('Incorrect input!!!');
  13.             IsCorrect := False;
  14.         end;
  15.         if (IsCorrect and (Number < Min) or (Number > Max)) then
  16.         begin
  17.             Writeln('Incorrect input!!!');
  18.             IsCorrect := False;
  19.         end;
  20.     until IsCorrect;
  21.     TakeInt := Number;
  22. end;
  23.  
  24.  
  25.  
  26. static int takeInt(int min,int max) {
  27.     int number = 0;
  28.     boolean isIncorrect;
  29.     do {
  30.         isIncorrect = false;
  31.         try {
  32.             number = Integer.parseInt(scan.nextLine());
  33.         } catch (NumberFormatException e) {
  34.             System.out.println("Incorrect input!!!");
  35.             isIncorrect = true;
  36.         }
  37.         if (!isIncorrect && (number < min || number > max)){
  38.             System.out.println("Incorrect input!!!");
  39.             isIncorrect = true;
  40.         }
  41.     }while (isIncorrect);
  42.     return number;
  43. }
Add Comment
Please, Sign In to add comment