Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.check;
- import java.util.Scanner;
- public class Main {
- 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 {
- if (in.hasNextInt()) {
- age = in.nextInt();
- IsCorrect = true;
- } else {
- in.nextLine();
- System.out.print(" Incorrect data entered ");
- }
- }
- 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