1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package QuizWeek1;
-
- public class LoopFun
- {
-
- /**
- * Given a number, return the factorial of that number.
- * For example, given 5, the factorial is 5 x 4 x 3 x 2 x 1 which should return 120.
- * @param number
- * @return the factorial of the number
- */
- public int factorial(int number){
- int factorial = 0;
- int i = 0;
- while (i <= number){
- i*=i;
- i++;
-
- }
- return factorial;
- }
-
- /**
- * Given a phrase, get the acronym of that phrase. Acronym is the combination of
- * the first character of each word in upper case.
- * For example, given "Ruby on Rails", this method will return "ROR"
- * @param phrase
- * @return Upper case string of the first letter of each word
- */
- public String acronym(String phrase) {
- int spaceIndex = phrase.indexOf(" ");
- char acro = phrase.charAt(spaceIndex+1);
- for (int i = 1; i < phrase.length(); i++){
- acro = Character.toUpperCase(phrase.charAt(spaceIndex+1));
- }
-
- return Character.toUpperCase(phrase.charAt(0)) + Character.toString(acro);
- }
-
- /**
- * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
- * intended audience. This method encrypt the message by shifting the letter by 3 characters. If the character is
- * at the end of the alphabet, it will wraps around.
- * For example:
- * 'a' => 'd'
- * 'w' => 'z'
- * 'x' => 'a'
- * 'y' => 'b'
- * @param word
- * @return the encrypted string by shifting each character by three character
- */
- public String encrypt(String word) {
- return null;
- }
- }
|