CSE 8B Lecture Notes - Lecture 10: Object Copying
Document Summary
@override public boolean equals(object o) { if(this instanceof o) { // return true if same, false otherwise return false; Recursion public static void foo(int x) { if(x > 1) foo(x 1); This recursive code will print out the numbers starting at 1 all the way to x public static void foo(int x) { This recursive code will print out the numbers starting at x all the way down to 1 public static int factorial(int n) { if(n <= 1) return 1; return n * factorial(n 1); This code find the factorial of a number n public static int search(double[] array, double tofind, int lastpos){ // base case 1 if last element is one we want, return its index if(array[lastpos] == tofind) return lastpos; // base case 2 else if last element is not one we want and there are. // no more to look at else if(lastpos == 0) return -1;