Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

y2k problem

807599Dec 12 2006 — edited Dec 12 2006
hi. here is my program for y2k detector
import java.util.Scanner;
class yDetector{
	public static void main(String args[]) {
		Scanner myScanner = new Scanner (System.in);
		int age;
		int year;
		int total;
		System.out.println("Enter your age ");
		age = myScanner.nextInt();
		System.out.println("Enter the year ");
		year = myScanner.nextInt();
		if ( year == 00) {
			year = 100;
			total = year - age;
			System.out.println(" Your age :" + total);
		}
		else {
			total = year - age;
			System.out.println("your age " + total);
		}
	}
}
This program works fine only for 00 for eg;
Enter your age 
29
Enter the year 
00
 Your age :71
Now my problem is what if a user enters 01 or 02 or 03 what kind of condition can i make so then it calculates the rite age any clues ?
i know i can do this easily if the year and age should be 4 digits like 1999 and year 2005 but i want the user to enter 2 digits for the age and year
Message was edited by:
fastmike

Message was edited by:
fastmike
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2007
Added on Dec 12 2006
7 comments
570 views