Advertisement
VadimThink

Java

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