Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Prompt
  5. {
  6. public static int getValue (String ask)
  7. {
  8. Scanner input = new Scanner(System.in);
  9. System.out.print(ask);
  10. int value = input.nextInt();
  11. return value;
  12. }
  13. public static int getValue (String ask, int min, int max)
  14. {
  15. Scanner input = new Scanner(System.in);
  16. System.out.print(ask);
  17. System.out.print(" from " + min + " to " + max + " : " );
  18. int value;
  19. do
  20. {
  21. value = input.nextInt();
  22. if (value < min || value > max)
  23. {
  24. System.out.print("\nTry again: ");
  25. }
  26. } while (value < min || value > max);
  27. return value;
  28. }
  29. public static double getValue (String ask, double min, double max)
  30. {
  31. Scanner input = new Scanner(System.in);
  32. System.out.print(ask);
  33. System.out.printf(" from %6.2f to %6.2f : ",min,max);
  34. double value;
  35. do
  36. {
  37. value = input.nextDouble();
  38. if (value < min || value > max)
  39. {
  40. System.out.printf("%n,Try again, from %6.2f to %6.2f : ",min,max);
  41. }
  42. } while (value < min || value > max);
  43. return value;
  44. }
  45.  
  46.  
  47. }
Add Comment
Please, Sign In to add comment