import java.util.Scanner;
public class JPA405 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int n;
System.out.print("Input the number n :");
n= keyboard.nextInt();
System.out.println("Ans : "+sum2(n));
}
static int sum2(int n) {
if(n>1){
return sum2(n-1)+2*n;
}
else{
return 2;
}
}
}
沒有留言:
張貼留言