Skip to content

Commit 28db03f

Browse files
committed
feat: Add SubstringsDemo class to demonstrate Java substring(beginIndex, endIndex) method
- Created a `SubstringsDemo` class with examples using the `substring(int beginIndex, int endIndex)` method. - Defined two sample strings: - `alphabet = "ABCDEFG"` (indexes A:0 to G:6) - `keyboard = "QWERTY"` (indexes Q:0 to Y:5) - Used `alphabet.substring(1, 7)` to extract "BCDEFG", which includes characters from index 1 up to (but not including) index 7. - Used `keyboard.substring(0, 5)` to extract "QWERT", which includes characters from index 0 up to index 5. - Printed both results to demonstrate how substring slicing works in Java. This commit serves as a practical illustration of extracting portions of strings using index ranges. Signed-off-by: Somesh diwan <[email protected]>
1 parent 7a38177 commit 28db03f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
public class SubstringsDemo
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class SubstringsDemo {
2+
public static void main(String[] args) {
53
String alphabet = "ABCDEFG";
64
//letter: index. A:0, B:1, C:2, D:3, E:4, F:5, G:6
5+
76
String keyboard = "QWERTY";
87
//letter: index. Q:0, W:1, E:2, R:3, T:4, Y:5
98

109
System.out.println(alphabet.substring(1,7));
1110
System.out.println(keyboard.substring(0,5));
1211
}
13-
}
12+
}

0 commit comments

Comments
 (0)