CSCI 202

Purpose

In this assignment you will write a recursive algorithm and use the debugger.

Due dates

This assignment must be submitted to the Moodle submission page for Homework 1 by 11:00 PM on Monday, 23 January. Your submission will consist of both a Java program and a screen shot.

Starting the assignment

Find a computer where you can run Java programs under NetBeans. Hopefully, it will be one you use at home.

The program

Write an program that prompts for two positive integers n and p from its main and calls a method that computes np mod 231 using the following recursive algorithm.

The “mod 231” may look scary, but it just allows you to ignore the overflow that occurs when multiplying large integers in Java.

Using the debugger

Run your program with n and p both set to 100. Use the NetBeans debugger to stop your program when the recursive exponentiation routine is entered with p equal to 12. Due to the limited precision of integers n should be 1874919424 at the point (because you get 1874919424 when you multiply 100000000 by 100000000 with Java 32-bit integers).

Take a snapshot of the debugger screen and save it to a file.

Here’s a picture of my program taken at the just the right time.
NetBeans debugger
The ugly orange box covers my program.