News for hackers. Stuff that matters.

My code does not work

I am trying to write a method that determines if the square of the age of a person is equal to the current year. For example a man was aged 43 in 1849 and the square of 43 is 1849. Below is my code for it but I dont know why my exception is not working because it is assumed that no body can live past 123 years

public class Augustus { private int year; private final static int RANGEOFLIVING=124; public static void main(String[] args) { Augustus y = new Augustus(1806); System.out.println( y.isAlive());

} public Augustus(int n){ year= n;

}

     public int SquareOfAge(int z){
    	 return z * z ;
     }
     
     public boolean isAlive(){
    	 
    	 for(int i=1;i<RANGEOFLIVING;i++)
    		 if( i *i==this.year++)
    			 return true;
    		 
    		 	 
    			  return false;
		
		
     }
}
( 3 comments | on HN )
Re:My code does not work by LukeFitz on Monday July 04, 2011 @08:44PM (#2728300)
Hi, this site unfortunately is not meant for discussing code issues such as this. Maybe you could hit up www.stackoverflow.com, and try there.
Re:My code does not work by benologist on Monday July 04, 2011 @08:45PM (#2728304)
Your description doesn't really seem to match your code. This is probably the code you describe:

    private static boolean Match(int age, int year)
    {
        return year == age*age; 
    }
Re:My code does not work by TMK on Monday July 04, 2011 @08:49PM (#2728312)
public boolean CmpSquareOfAgeToYear(int age, int year) {

    if(age * age == year) {

       return true;

    } else {

       return false;

    }

}