I have this recursion that I created the main for but cant figure out the trace as to why it provides the output it does. Can someone provide me a trace?
import java.util.*; public class oddRecurrsion{ public static void main(String[] args){ Scanner stdin = new Scanner(System.in); System.out.print("Enter an integer: "); int input = stdin.nextInt(); System.out.println("Integer \"" + input + "\" equals " + odd(input)); } //end main public static int odd(int number) { if (number == 1) return 1; else return (2 * number - 1) + odd(number - 1); } //end odd } // end class
OUTPUT:
Enter an integer: 5
Integer "5" equals 25
Enter an integer: 3
Integer "3" equals 9