y2k problem

hi. here is my program for y2k detector

import java.util.Scanner;

class yDetector{

publicstaticvoid 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

[1832 byte] By [fastmikea] at [2007-11-26 12:21:46]
# 1
I dont get it, what is your program supposed to do?
CaptainMorgan08a at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 2
it is suppose to calculate the age .
fastmikea at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 3
> it is suppose to calculate the age .Based on the year and your age? Could you show me some sample output (of what its supposed to do)?
CaptainMorgan08a at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 4

sure

it is suppose to calculate the age .

Enter your age

80

Enter the year

99

your age 19

Enter your age

80

Enter the year

00

your age 20

Enter your age

80

Enter the year

02

your age -78

This is whats happening if i enter 01 or 02 or 03

fastmikea at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 5
Have an if statement that checks if the year is less than your age. If it is, then add 100 to the year.
CaptainMorgan08a at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 6

Ahhhhhh Great Cap You got it..

import java.util.Scanner;

class groundBeef {

public static void main(String args[]) {

Scanner myScanner = new Scanner (System.in);

int age;

int year;

int total;

System.out.println("Enter year of birth ");

age = myScanner.nextInt();

System.out.println("current year ");

year = myScanner.nextInt();

if ( year < age) {

year += 100;

total = year - age;

System.out.println(" Your age :" + total);

}

else {

total = year - age;

System.out.println("your age " + total);

}

}

}

sample output

Enter year of birth

80

current year

02

Your age :22

So stupid of me lol. Thanks neways

fastmikea at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...
# 7
> So stupid of me lol. Thanks newaysNo problem.
CaptainMorgan08a at 2007-7-7 15:14:03 > top of Java-index,Archived Forums,Socket Programming...