// 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.

This is the code I wrote, it has no errors or anything but when I run it nothing happens. Can anyone tell me what I am doing wrong?

import javax.swing.JOptionPane;
public class SquareAge {


    public static void main (String [] args) {
}
    int MAX_LIFE_EXPECTANCY = 123;
    int startYear = 2012; {
    int age =0; 
    for (age=0; age<=MAX_LIFE_EXPECTANCY; age++); {
        double currentYear = (startYear+age);
        double currentAge = (Math.sqrt(currentYear));
        double bornYear = (currentYear - currentAge);

          if ((currentAge == (int)currentAge) && (bornYear <= currentYear));
          {
          JOptionPane.showMessageDialog (null, "currentYear, bornYear , currentAge");
    }
    }
    }
}

please guys, has to be submitted tonight and I'm so confused :(

Know this might be too late, but as I understand the task:

for (int i = 1; i <= MAX; i++)
{
    System.out.println("Age: " + i + " squared: " + i*i);
}

Would give you all neccessary values, like:
Age : 44 squared = 1936
Age : 45 squared = 2025

These are the only ages that will give a square value within our lifetime.

So unless you were born in either 1936-44 = 1892 or 2025-45 = 1980,
you will never experience having your age squared being the current year.

Could be I'm off my game here, as it's 3:30 here, and I have to go to bed... But that's how I read the assignment...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.