-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringbuf.java
More file actions
30 lines (27 loc) · 1.32 KB
/
Stringbuf.java
File metadata and controls
30 lines (27 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class Stringbuf
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("\n\t\t\tString operations using StringBuffer class");
System.out.println("\t\t\t-----------------------------------------");
System.out.print("\nEnter a string : ");
StringBuffer str = new StringBuffer(scanner.nextLine());
System.out.println("\n\t\t\t1. Length of the String");
System.out.println("\t\t\t---------------------");
System.out.println("\tLength of the string: " + str.length());
System.out.println("\n\t\t\t2. Reverse the String");
System.out.println("\t\t\t---------------------");
System.out.println("\tReversed String: " + str.reverse());
str.reverse(); //To get again original string
System.out.println("\n\t\t\t3. Delete the String");
System.out.println("\t\t\t---------------------");
System.out.print("Enter starting index to delete: ");
int start = scanner.nextInt();
System.out.print("Enter ending index to delete: ");
int end = scanner.nextInt();
scanner.nextLine(); // Consume newline character
str.delete(start, end);
System.out.println("\n\tString after deletion : " + str);
}
}