/* * Created on Oct 13, 2004 * This code corresponds to the worksheet on proof by * mathematical induction given out in class. * * @author tanimoto */ public class Induction { static int countA; static int countB; public static void main(String[] args) { int p = 10; System.out.println("p = " + p); loopA(p); System.out.println("countA = " + countA); loopB(p); System.out.println("countB = " + countB); } static void loopA(int n) { countA = 0; for (int i = 0; i < n; i++) { int lim = 2*i+1; for (int j = 0; j < lim; j++) { for (int k = 0; k < lim; k++) { countA++; countA++; countA++; } } } } static void loopB(int n) { countB = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < (2*n)-1; j++) { for (int k = 0; k < (2*n)+1; k++) { countB++; } } } } }