Recursion - if(b == 0){ return 1; } else{ return a *...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
package lab11; p public class Recursion { p public static void main(String[] args) { System.out.println(power(2,8)); System.out.println(getPyramidCount(7)); } public static int power(int a, int b){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(b == 0){ return 1; } else{ return a * power(a, b-1); } } public static int getPyramidCount(int a){ if(a == 0){ return 0; } return power(a,2) + getPyramidCount(a-1); } }...
View Full Document

Ask a homework question - tutors are online