Wednesday, January 14, 2009

Create a Java program to give you acceptable age ranges

Take your age divide by two and add seven...this is the upper and lower bound of the ages you can date.

http://www.xkcd.com/314/

Here's one solution:

int myAge = 20;
double acceptableRange = (myAge/2)+7;
// System.out.println(acceptableRange);
double difference = myAge - acceptableRange;
// System.out.println(difference + " is the difference");
System.out.println("You are " + myAge + " years old");
System.out.println("The oldest you can date is "+ (myAge + difference));
System.out.println("The youngest you can date is " + acceptableRange);

No comments: