Skip to content

Commit 56cca7f

Browse files
authored
Merge pull request #4 from code-for-tomorrow/Josh-J-StringSlicer
Create String Slicer problem (Josh J)
2 parents e6eacd2 + 62625d9 commit 56cca7f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)