Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class laba1_2
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner in = new Scanner(System.in);
  7. System.out.print("Enter your age: ");
  8. boolean IsCorrect = false;
  9. int age = 0;
  10. do {
  11. String str_age = in.next();
  12. if (str_age.matches("[0-9]+"))
  13. {
  14. age = Integer.parseInt(str_age);
  15. break;
  16. }
  17. else
  18. {
  19. System.out.print(" Incorrect data entered ");
  20. IsCorrect = false;
  21. }
  22. }
  23. while (!IsCorrect) ;
  24. if (age >= 18 && age < 100)
  25. {
  26. System.out.print("You have the right to vote");
  27. } else if
  28. (age < 18 && age > 0)
  29. {
  30. age = 18 - age;
  31. System.out.print("The number of years after which you can vote - " + age);
  32. } else {
  33. System.out.print(" Incorrect data entered ");
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement