r/javahelp • • 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

6 comments sorted by

View all comments

3

u/SikhGamer Oct 19 '13

I think you may be over thinking the problem.

43 x 43 = 1849
44 x 44 = 1936
45 x 45 = 2025

And so on. Only the age changes. You know the age is going to start at 43 and finish at 123. The rest is a simple loop will do. I think you are aiming for this kind of output: http://pastebin.com/F1gZBPPa

0

u/ranar1 Oct 20 '13

Yeah that's correct but how do we really do that? I'm sorry I recently started learning java so I'm kind of slow in picking stuff up.

3

u/SikhGamer Oct 20 '13

I gave you all the clues you needed. A loop, starting at 43 and finishing on 123. It's pretty much what you've posted in your OP.