Problems For Algorithm Development: Java Programming
Problems For Algorithm Development: Java Programming
(COMPROG 2526)
07:30 - 09:30 AM TTHS P508
import java.util.*;
public class Prob25_CAYABYAB {
public static void main(String[] args) {
26. Input and print a number (NUM), its reverse by using operators div and mod. If the
last digit is zero, replace it with a one(1) before reversing the number. Output also
the sum of all the digits.
Example 1:
Input: 543267
Output: 762345 (reversed value)
Sum of all digits: 27
Example 2:
Input: 14980 (add 1 to n such that n=14981.)
Output: 18941 (reversed value)
Sum of all digits: 23
30. Calculate and output the volume and area of spheres using the formula:
V = (4PiR3)/3 A = 4PiR2 where R is the radius of the sphere, from 1 to 20.
31. Using the equation Y=2+4X-X2, compute and output values of Y for values of X from 1
to 20, and in increment of 1.
32. An object falling from rest in a vacuum falls 16 feet on the first second, 48 feet
on the 2nd second, 80 feet on the third second, 112 feet the 4th second and so on. Output
the distance traveled by the object after 15 seconds.
Output the number of terms required and the value of S before S exceeds 3.1.
Example:
1st term: S = 1;
2nd term: S = 1 + 1/2 = 1.5;
3rd term: S = 1 + 1/2 + 1/3 = 1.8333;
4th term: S = 1 + 1/2 + 1/3 + 1/4 = 2.08333;
5th term: S = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.2833;
...
nth term: S = ?
public class Prob34_CAYABYAB {
public static void main(String[] args) {
38. A ball is dropped from an initial height of 50 feet. If the ball bounces 2/3 of
the previous height, make a program that will calculate and print the total distance
traveled by the ball after the 10th bounce.