Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions beginner_programming/age_counter/java/Count_Age.java
Original file line number Diff line number Diff line change
@@ -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.");

}
}