File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
src/com/codefortomorrow/beginner/chapter3 Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .codefortomorrow .beginner .chapter3 .practice ;
2
+
3
+ /*
4
+ * Use String Methods to convert the following strings to the results
5
+ * a) "A Tale of Two Cities" -> "WO CIT"
6
+ * b) "A Handmaid's Tale" -> "s"
7
+ * c) "wE LoVe tO CoDe" -> "e love to code"
8
+ */
9
+
10
+ public class StringSlicer {
11
+ public static void main (String [] args ) {
12
+ // Write Code here
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .codefortomorrow .beginner .chapter3 .solutions ;
2
+
3
+ /*
4
+ * Use String Methods to convert the following strings to the results
5
+ * a) "A Tale of Two Cities" -> "WO CIT"
6
+ * b) "A Handmaid's Tale" -> "s"
7
+ * c) "wE LoVe tO CoDe" -> "e love to code"
8
+ */
9
+ public class StringSlicer {
10
+ public static void main (String [] args ) {
11
+ // Initialize original strings
12
+ String s1 = "A Tale of Two Cities" ;
13
+ String s2 = "A Handmaid's Tale" ;
14
+ String s3 = "wE LoVe tO CoDe" ;
15
+
16
+ // Use substring + uppercase on the first one
17
+ System .out .println (s1 .toUpperCase ().substring (11 , 17 ));
18
+
19
+ // Use charAt for s2
20
+ System .out .println (s2 .charAt (11 ));
21
+
22
+ // Use the single-argument substring + lowercase
23
+ System .out .println (s3 .toLowerCase ().substring (1 ));
24
+ // You can also use substring(1,15)
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments