Would anyone be able to explain these methods with a few comments line. They are for squaring a number. One is using recursion, implementation and another is just normal
public static int sq(int n)
{
int i = 0 ;
int result = 0 ;
while(i < n){
result = result + 2*i + 1 ;
i = i + 1 ;
}
return result ;
}
public static int recSq(int n)
{
if(n == 0){
return 0 ;
} else {
return recSq(n - 1) + 2*(n - 1) + 1 ;
}
}
public static int implementSq(int n)
{
int i ;
int result = 0 ;
for(i = 0 ; i < n ; i++){
result = result + 2*i + 1 ;
}
return result ;
}