hey,

could u help me with my java programming? i have this problem: Thanks a lot!!!!

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.

## Recommended Answers

Jump to Postwhat your question about the problem.

It seems pretty straight forward to me

use a condition that checks if the square of the current age is equal to the current year until the age of 123 using a loop

Jump to PostFor mathematical part, your starting year is this year (2012). The year is 0, and there are people age from 0 (new born today) to 123 (turn 123 this year). The next year (2013), the year is 1, you aren't going to count anyone who is born in that year …

Jump to PostBefore going into your code, I would like to talk about code convention. For naming convention, please read this link. There are certain reasons why there are rules.

Now back to your code. …

Jump to PostIt would be like this:

`current_year<-2012 for i=current_year to current_year+123 do for j=0 to 124 do if i*i==j then print year=j print age=i print birth year=j-i end_if end_for end_for`

Remember, this is written in pseudo-code, so you'll have to implement it.

Jump to PostLucaci, your method is too slow and contain unnecessary inner loop. The value of square root of a year will never be greater than 123 and only one born-year will match the square root value, so iterate from 0 to 124 to find a match square value is overkilled.

## All 17 Replies

zeroliken
79
Nearly a Posting Virtuoso

Taywin
312
Posting Virtuoso

jalpesh_007
-3
Newbie Poster

Kunai9292
0
Newbie Poster

Kunai9292
0
Newbie Poster

Taywin
312
Posting Virtuoso

Kunai9292
0
Newbie Poster

Lucaci Andrew
140
Za s|n

Taywin
312
Posting Virtuoso

Kunai9292
0
Newbie Poster

Kunai9292
0
Newbie Poster

Taywin
312
Posting Virtuoso

Kunai9292
0
Newbie Poster

sesayed
0
Newbie Poster

rayzor1394
0
Newbie Poster

javaCONFUSEDDD
0
Newbie Poster

TylerD75
0
DaniWeb Newbie

Be a part of the DaniWeb community

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