Created
March 12, 2014 03:54
-
-
Save brijeshb42/9500574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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