Wednesday, August 7, 2013

java Program to Illustrate the use of Methods of StringBuffer Class

 Program to Illustrate the use of Methods of StringBuffer Class

import java.io.*;
import java.lang.*;
class Stringb
{
public static void main(String args[])
{
try
{
StringBuffer str=new StringBuffer("Radha Garg");
System.out.println("\n1.Length\n2.Capacity
\n3.Setlength\n4.Charat\n5.Setcharat
\n6.Append\n7.Deletecharat\n8.Substring
\n9.Substring1\n10.Insert\n11.Reverse");
System.out.println("Enter ur chioce");
DataInputStream ds = new DataInputStream(System.in);
int ch = Integer.parseInt(ds.readLine());
switch(ch)
{
case 1:
System.out.println("The length of the
string is:" + str.length());
break;
case 2:
System.out.println("The capacity of
String:" + str.capacity());
break;
case 3:
str.setLength(15);
System.out.println("Set length of String:"
+ str.length());
break;
case 4:
System.out.println("The character at 6th
position:" + str.charAt(5));
break;
case 5:
str.setCharAt(2,'u');
System.out.println("The string after
setting position is:" +str);
break;
case 6:
System.out.println("The string after
appending:" + str.append(" Sohni"));
break;
case 7:
System.out.println("The string after
deletion:" + str.deleteCharAt(7));
break;
case 8:
System.out.println("The substring is:" +
str.substring(2));
break;
case 9:
System.out.println("The subsstring2 is:" +
str.substring(3,8));
break;
case 10:
System.out.println(" The string after
insertion is:" + str.insert(6,'m'));
break;
case 11:
System.out.println("The string after
reverse is:" + str.reverse());
}
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
}
Output:

No comments:

Post a Comment