Skip to content

Commit 59ef296

Browse files
committed
Create StringSlicer Problem
Some practice with String Methods
1 parent 5c5f81e commit 59ef296

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

StringSlicer

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class StringSlicer{
2+
public static
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class StringSlicer{
2+
/*
3+
Use String Methods to convert the following strings to the results
4+
a) "A Tale of Two Cities" -> "WO CIT"
5+
b) "A Handmaid's Tale" -> "s"
6+
c) "wE LoVe tO CoDe" -> "we love to cod"
7+
*/
8+
public static void main(String[] args){
9+
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class StringSlicer{
2+
/*
3+
Use String Methods to convert the following strings to the results
4+
a) "A Tale of Two Cities" -> "WO CIT"
5+
b) "A Handmaid's Tale" -> "s"
6+
c) "wE LoVe tO CoDe" -> "e love to code"
7+
*/
8+
public static void main(String[] args){
9+
//Initialize original strings
10+
String s1 = "A Tale of Two Cities";
11+
String s2 = "A Handmaid's Tale";
12+
String s3 = "wE LoVe tO CoDe";
13+
14+
//Use substring + uppercase on the first one
15+
System.out.println(s1.toUpperCase().substring(11,17));
16+
17+
//Use charAt for s2
18+
System.out.println(s2.charAt(11));
19+
20+
//Use the single-argument substring + lowercase
21+
System.out.println(s3.toLowerCase().substring(1));
22+
//You can also use substring(1,13)
23+
}
24+
}

0 commit comments

Comments
 (0)