Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class laba1_2
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- System.out.print("Enter your age: ");
- boolean IsCorrect = false;
- int age = 0;
- do {
- String str_age = in.next();
- if (str_age.matches("[0-9]+"))
- {
- age = Integer.parseInt(str_age);
- break;
- }
- else
- {
- System.out.print(" Incorrect data entered ");
- IsCorrect = false;
- }
- }
- while (!IsCorrect) ;
- if (age >= 18 && age < 100)
- {
- System.out.print("You have the right to vote");
- } else if
- (age < 18 && age > 0)
- {
- age = 18 - age;
- System.out.print("The number of years after which you can vote - " + age);
- } else {
- System.out.print(" Incorrect data entered ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement