Lab Assignment 6
CS201, Spring 2004


1. Number of terms to get Pi (5pt). Complete the program PiTerms.java.

2. Distance (5pt). The distance between two points (x1,y1) and (x2,y2) can be calculated as sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ). Write a method distance which take four parameters x1, y1, x2, y2, and returns the distance between the two points (x1,y1) and (x2,y2). Write a program to test your method.

3. Reverse a five digit number. Write a method reverse which takes a 5-digit integer as parameter, and returns an integer which is the original integer with the digits in reversed order. For example, reverse(12343) should return 34321. Write a Java program to test your method. [Hint: first seperate the integer into digits like we did in Palindrome5.java, then re-assemble the digits as digit5*10000+digit4*1000+digit3*100+digit2*10+digit1.]