C311 Assignment 13 -- (Really) Basic Java

(or ... ``How to write small C programs in Java'')

Due Monday, April 15, at 9 AM

Submit via email

Write the Java class Basic with the following public, static methods:

int sum_of_squares(int x, int y)
should take integers x and y and return the sum of the squares of x and y.
int fact(int n)
should take an integer n and return the factorial of n. You may assume n is non-negative.
int fib(int n)
should take an integer n and return the nth fibonacci number. You may assume n is non-negative.
int num_reverse(int n)
should take an integer n and return an integer whose digits are the reverse of n. You may want to use the `%' operator (remainder) and/or the `/' operator (integer division). If you do define a ``helper'' method, it should be static and should not be public. You may assume n is non-negative.

Testing

If the following java program (in the file Test.java) were compiled:

abstract class Test {
  public static void main(String[] args) {
    System.out.println(Basic.sum_of_squares(3, 4));
    System.out.println(Basic.fact(5));
    System.out.println(Basic.fib(8));
    System.out.println(Basic.num_reverse(8675309));
  }
}
The results of
java Test
would be
25
120
21
9035768

Submission

Write your answers to the exercises in a file (with comments, following the proper indentation rules, whatever they may be for Java), and send that file to

c311@lakshmi.cs.indiana.edu
with the subject line
13
Assuming you've saved your homework in the file ``asgn.ss'' in the current directory, one way to submit is with the command:
Mail -s "13" c311@lakshmi.cs.indiana.edu < asgn.ss
The ``grader'' program will not test your submission, it will only confirm the receipt of the submission and save it.


Back to the c311 page

ehilsdal@cs.indiana.edu