Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. package topic05_work02;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Validity2 {
  6.  
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9.  
  10. String number;
  11. double x;
  12.  
  13. Scanner input = new Scanner(System.in);
  14.  
  15. System.out.println("Enter a positive value < 100: ");
  16. number = input.nextLine();
  17. x = Double.parseDouble(number);
  18.  
  19. do {
  20.  
  21. validity(x);
  22.  
  23. if (validity(x) == false) {
  24. System.out.println("Invalid input!");
  25. System.out.println("Enter a positive value < 100: ");
  26. number = input.nextLine();
  27. x = Double.parseDouble(number);
  28. }
  29. else {
  30. System.out.println("Great job!");
  31. }
  32.  
  33. }
  34.  
  35. while (validity(x) == false);
  36. System.out.println("Great job!");
  37.  
  38. }
  39.  
  40. public static boolean validity(double n) {
  41. if (0 < n && n < 100) {
  42. return true;
  43. }
  44.  
  45. else {
  46. return false;
  47. }
  48.  
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement