-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram33_StringBuffer.java
More file actions
37 lines (28 loc) · 1.03 KB
/
Program33_StringBuffer.java
File metadata and controls
37 lines (28 loc) · 1.03 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
31
32
33
34
35
36
37
// Write a java program that uses any 5 methods of "StringBuffer" class.
// Date : 31/03/2024, Author : Yash Wadhvani
import java.util.Scanner;
public class Program33_StringBuffer {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
StringBuffer s1, s2, s3, s4, s5;
System.out.println("Enter a String :");
str = sc.next();
sc.close();
s1 = new StringBuffer(str);
s1.append(" Butterfly!");
System.out.println("New String : " + s1 + "\n");
s2 = new StringBuffer(str);
s2.delete(2, 3);
System.out.println("New String : " + s2 + "\n");
s3 = new StringBuffer(str);
s3.insert(1, str);
System.out.println("New String : " + s3 + "\n");
s4 = new StringBuffer(str);
s4.replace(2, 5, "yya!");
System.out.println("New String : " + s4 + "\n");
s5 = new StringBuffer(str);
s5.reverse();
System.out.println("New String : " + s5 + "\n");
}
}