From bfc8b89157f3169f201517bffd5f151475ac55da Mon Sep 17 00:00:00 2001 From: dogayalcin Date: Wed, 27 Oct 2021 15:29:20 +0300 Subject: [PATCH] add counter age for java --- .../age_counter/java/Count_Age.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 beginner_programming/age_counter/java/Count_Age.java diff --git a/beginner_programming/age_counter/java/Count_Age.java b/beginner_programming/age_counter/java/Count_Age.java new file mode 100644 index 000000000..e3bf388e4 --- /dev/null +++ b/beginner_programming/age_counter/java/Count_Age.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class Count_Age{ + + public static void main(String[] args){ + + Scanner in = new Scanner(System.in); + System.out.println("Please enter your birth year(YYYY) :"); + int birth_year = in.nextInt(); + System.out.println("Please enter your birth month(MM) :"); + int birth_month = in.nextInt(); + System.out.println("Please enter current year(YYYY) :"); + int current_year = in.nextInt(); + System.out.println("Please enter current month(MM) :"); + int current_month = in.nextInt(); + + + int year = current_year - birth_year; + int month = current_month - birth_month; + if(month<0){ + year--; + month+=12; + } + + System.out.println("Your age is " + year + " years and " + month + " months."); + + } +} \ No newline at end of file