
Create two strings s1=â??Javaâ?? and s2=â??Programmingâ?? using string Buffer class and perform the following operations. i) Append s1 and s2. ii) Reverse string s1. iii) Find length of string s1 and s2. iv) Replace string s1 to â??Simpleâ??. v) Extract 0th to 6th character from string s2 into s3.

import java.util.*;
class StringExample {
public static void main(String[] args) {
String s1="Java";
String s2="Programming";
StringBuffer buffer=new StringBuffer();
buffer.append(s1);
buffer.append(s2);
System.out.println(buffer.toString());
String reversest = new StringBuffer(s1).reverse().toString();
System.out.println("Reversed string1: "+reversest);
int len1=s1.length();
int len2=s2.length();
System.out.println("Length of string 1= "+len1+" and string 2= "+len2);
String repString=s1.replace(s1,"Simple");
System.out.println(repString);
String s3=s2.substring(0,6);
System.out.println(s3);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.