Skip to content

Instantly share code, notes, and snippets.

@brijeshb42
Created March 12, 2014 03:54
Show Gist options
  • Save brijeshb42/9500574 to your computer and use it in GitHub Desktop.
Save brijeshb42/9500574 to your computer and use it in GitHub Desktop.
import java.util.*;
class Test{
public static void main(String[] args){
int n,c;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a negative integer: ");
n = sc.nextInt();
if(n>0){
System.out.println("Enter a -ve integer.");
return;
}
c= cube(n);
System.out.println("Cube(n)= "+c);
}
private static int cube(int n){
if(n==0)
return 0;
return cube(n+1) + -3*n*n - 3*n -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment