LoopFun.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. public class LoopFun
  2. {
  3. /**
  4. * Given a number, return the factorial of that number.
  5. * For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
  6. * @param number
  7. * @return the factorial of the number
  8. */
  9. public int factorial(int number){
  10. {
  11. if (number == 0)
  12. return 1;
  13. return number*factorial(number-1);
  14. }
  15. }
  16. /**
  17. * Given a phrase, get the acronym of that phrase. Acronym is the combination of
  18. * the first character of each word in upper case.
  19. * For example, given "Ruby on Rails", this method will return "ROR"
  20. * @param phrase
  21. * @return Upper case string of the first letter of each word
  22. */
  23. public String acronym(String phrase) {
  24. String newstring[] = phrase.split(" ");
  25. for (i=0;i<newstring.length;i++){
  26. newstring[i].
  27. }
  28. return null;
  29. }
  30. /**
  31. * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
  32. * intended audience. This method encrypt the message by shifting the letter by 3 characters. If the character is
  33. * at the end of the alphabet, it will wraps around.
  34. * For example:
  35. * 'a' => 'd'
  36. * 'w' => 'z'
  37. * 'x' => 'a'
  38. * 'y' => 'b'
  39. * @param word
  40. * @return the encrypted string by shifting each character by three character
  41. */
  42. public String encrypt(String word) {
  43. return null;
  44. }
  45. }