r/javahelp • u/ranar1 • Oct 19 '13
Please help me with this Java Question
The mathematician Augustus De Morgan was aged 43 in the year 1849AD. This is interesting because 43 squared is 1849, ie, in 1849 his age was the square root of the year. Given that no person has ever lived longer than 123 years (and assuming that no one ever will), write a Java application that will determine if it is possible that anyone who is alive today is, has ever been, or will ever be alive in a year that is the square of their age. If it is possible, your program should print out the years in which it happens and the ages that the people concerned will have in those years.
Here is what I have worked on till now
public class SquareAge {
public static final int START_YEAR=2013;
public static final int YEAR_MAX= 2136;
public static final int YEAR_MIN=1890;
public static final int MAXIMUM_AGE=123;
public static void main(String[] args) {
int age;
for (age=0; age<=MAXIMUM_AGE; age++);
{
int agesquare=age*age;
if (agesquare>=YEAR_MIN && agesquare<=YEAR_MAX && age>=agesquare-START_YEAR)
{
System.out.print("the age is " + age + " the year is " + agesquare);
}
else
{
System.out.print("none");
}
}
}
}
0
Upvotes
3
u/SikhGamer Oct 19 '13
I think you may be over thinking the problem.
And so on. Only the age changes. You know the age is going to start at
43and finish at123. The rest is a simple loop will do. I think you are aiming for this kind of output: http://pastebin.com/F1gZBPPa