thorax232

Challenge #2

Feb 21st, 2013
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Challenge #2
  2.  
  3. Exercise #1:
  4. Write a program that displays the following table (use Math.POW and equations):
  5. a a^2 a^3
  6. 1 1 1
  7. 2 4 8
  8. 3 9 27
  9. 4 16 64
  10.  
  11. Exercise #2:
  12. Write a program the displays the result of (--- notes division):
  13. 9.5 * 4.5 - 2.5 * 3
  14. -------------------
  15. 43.5 - 3.5
  16.  
  17. Exercise #3:
  18. Write a program that displays the result of:
  19. 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
  20.  
  21. Exercise #4:
  22. PI can be computed using the following formula:
  23. PI = 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ....)
  24. Write a program that display the result of 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11)
  25. and 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13)
  26. NOTE: Use 1.0 instead of 1.
  27.  
  28. Exercise #5:
  29. Write a program that displays the area and perimeter of a circle that has a radius of 5.5. (Assign 5.5 to variable radius) using the following formula.
  30. perimeter = 2 * radius * pi
  31. area = radius * radius * pi (Use Math.pow)
  32.  
  33. Exercise #6:
  34. Write a program that displays the area of a rectangle wit the width of 4.5 and height of 7.9 using the following formula.
  35. area = width * height
  36.  
  37. Exercise #7 (Here's where it gets tricky, don't be afraid to plan out your program with pen in paper before starting, have patience, play with and test your program as you go, there's no shame in taking a day or two to figure things out):
  38. Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. Write a program that displays the average speed in miles per hour. (Note that 1 mile is 1.6 kilometers.)
  39.  
  40. Exercise #8:
  41. The U.S. Census Bureau projects population based on the following assumptions:
  42. - One birth every 7 seconds
  43. - One death every 13 seconds
  44. - One new immigrant every 45 seconds
  45.  
  46. Write a program to display the population for each of the next five years. Assume the current population is 312,032,486 and one year has 365 days. Hint: In Java, if two integers perform division, the result is an integer. The fraction part is truncated. For example, 5/4 is 1 (not 1.25) and 10/4 is 2 (not 2.5)
  47.  
  48. Exercise #9:
  49. Assume a runner runs 24 miles in 1 hour, 40 minutes and 35 seconds. Write a program that displays the average speed in kilometers per house. (Note that 1 mile is 1.6 kilometers)
Advertisement
Add Comment
Please, Sign In to add comment