My code does not work

1 points by logic101 ↗ HN
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

[ 2.7 ms ] story [ 18.7 ms ] thread
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.
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; 
    }
public boolean CmpSquareOfAgeToYear(int age, int year) {

    if(age * age == year) {

       return true;

    } else {

       return false;

    }

}