#41 JSC

開啟中
jasamuels 請求將 1 次程式碼提交從 jasamuels/JavaStringCheese:master 合併至 master
共有 2 個檔案被更改,包括 25 行新增10 行删除
  1. 二進制
      StringParser.class
  2. 25
    10
      StringParser.java

二進制
StringParser.class 查看文件


+ 25
- 10
StringParser.java 查看文件

@@ -15,7 +15,7 @@ public class StringParser
15 15
      */
16 16
     public static String upperCaseString(String s)
17 17
     {
18
-        return null;
18
+        return s.toUpperCase();
19 19
     }
20 20
 
21 21
     /**
@@ -26,7 +26,7 @@ public class StringParser
26 26
      * @return String
27 27
      */
28 28
     public static String lowerCaseString(String s) {
29
-        return null;
29
+        return s.toLowerCase();
30 30
     }
31 31
 
32 32
     /**
@@ -37,7 +37,9 @@ public class StringParser
37 37
      * @return String
38 38
      */
39 39
     public static Character getFirstCharacter(String s) {
40
-        return null;
40
+        String convert = s.substring(0,1);
41
+        char solution = convert.charAt(0);
42
+        return solution;
41 43
     }
42 44
 
43 45
     /**
@@ -49,7 +51,10 @@ public class StringParser
49 51
      * @return String
50 52
      */
51 53
     public static Character getNthCharacter(String s, Integer n) {
52
-        return null;
54
+        int firstnum = n + 1;
55
+        String thechar = s.substring(n,firstnum);
56
+        char itsthechar = thechar.charAt(0);
57
+        return itsthechar;
53 58
     }
54 59
 
55 60
     /**
@@ -60,7 +65,9 @@ public class StringParser
60 65
      * @return String
61 66
      */
62 67
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
68
+        int length = s.length();
69
+        String upperchar = s.substring(0,1).toUpperCase();
70
+        return upperchar + s.substring(1,length);
64 71
     }
65 72
 
66 73
     /**
@@ -72,7 +79,12 @@ public class StringParser
72 79
      * @return String
73 80
      */
74 81
     public static String camelCaseString(String s) {
75
-        return null;
82
+    String[] splitem = s.split("\\s+");
83
+    String upperchar1 = splitem[0].substring(0,1).toUpperCase();
84
+    String upperchar2 = splitem[1].substring(0,1).toUpperCase();
85
+    String lowerchar1 = splitem[0].substring(1,splitem[0].length()).toLowerCase();
86
+    String lowerchar2 = splitem[1].substring(1,splitem[1].length()).toLowerCase();
87
+    return upperchar1 + lowerchar1 + upperchar2 + lowerchar2;
76 88
     }
77 89
 
78 90
     /**
@@ -84,7 +96,10 @@ public class StringParser
84 96
      * @return String
85 97
      */
86 98
     public static String snakeCaseString(String s) {
87
-        return null;
99
+    String[] splitem = s.split("\\s+");
100
+    String first = splitem[0].toLowerCase();
101
+    String second = splitem[1].toLowerCase();
102
+    return first + "_" + second;
88 103
     }
89 104
 
90 105
     /**
@@ -95,7 +110,7 @@ public class StringParser
95 110
      * @return String
96 111
      */
97 112
     public static Integer getLength(String s) {
98
-        return null;
113
+        return s.length();
99 114
     }
100 115
 
101 116
     /**
@@ -109,7 +124,7 @@ public class StringParser
109 124
      * @return String
110 125
      */
111 126
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
127
+        if (s1 == s2) {return true;} else {return false;}
113 128
     }
114 129
 
115 130
     /**
@@ -123,6 +138,6 @@ public class StringParser
123 138
      * @return String
124 139
      */
125 140
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
141
+        return s1.equals(s2);
127 142
     }
128 143
 }