|
@@ -8,7 +8,11 @@ public class LoopFun
|
8
|
8
|
* @return the factorial of the number
|
9
|
9
|
*/
|
10
|
10
|
public int factorial(int number){
|
11
|
|
- return -1;
|
|
11
|
+ int total = 1;
|
|
12
|
+ for(int i = number; i > 0; i--){
|
|
13
|
+ total = i * total;
|
|
14
|
+ }
|
|
15
|
+ return total;
|
12
|
16
|
}
|
13
|
17
|
|
14
|
18
|
/**
|
|
@@ -19,7 +23,21 @@ public class LoopFun
|
19
|
23
|
* @return Upper case string of the first letter of each word
|
20
|
24
|
*/
|
21
|
25
|
public String acronym(String phrase) {
|
22
|
|
- return null;
|
|
26
|
+ StringBuilder finalString = new StringBuilder();
|
|
27
|
+ //ALWAYS TAKES FIRST LETTER
|
|
28
|
+ finalString.append(phrase.charAt(0));
|
|
29
|
+ for(int i = 0; i < phrase.length(); i++){
|
|
30
|
+ //CHECKS IF THERES A SPACE
|
|
31
|
+ if(phrase.charAt(i) == ' ') {
|
|
32
|
+ //IF THERE IS IT ADD IT TO OUR STRING
|
|
33
|
+ i++;
|
|
34
|
+ finalString.append(phrase.charAt(i));
|
|
35
|
+ }
|
|
36
|
+ }
|
|
37
|
+ //TURNS STRINGBUILDER INTO STRING
|
|
38
|
+ String answer = "" + finalString;
|
|
39
|
+ //MAKES STRING ALL CAPITALS
|
|
40
|
+ return answer.toUpperCase();
|
23
|
41
|
}
|
24
|
42
|
|
25
|
43
|
/**
|
|
@@ -35,6 +53,19 @@ public class LoopFun
|
35
|
53
|
* @return the encrypted string by shifting each character by three character
|
36
|
54
|
*/
|
37
|
55
|
public String encrypt(String word) {
|
38
|
|
- return null;
|
|
56
|
+ String newString = "";
|
|
57
|
+ for(int i = 0; i < word.length(); i++){
|
|
58
|
+ char encrypted = word.charAt(i);
|
|
59
|
+ int number = (int) encrypted;
|
|
60
|
+ if(number <= 119){
|
|
61
|
+ char newChar = (char)(number + 3);
|
|
62
|
+ newString = newString + newChar;
|
|
63
|
+ } else if(number >= 118){
|
|
64
|
+ char newChar = (char)(number - 23);
|
|
65
|
+ newString = newString + newChar;
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+ System.out.println((char) 97);
|
|
69
|
+ return newString;
|
39
|
70
|
}
|
40
|
71
|
}
|